CRMDataPipelineEnvClient, the Pydantic action and observation models, and the REST API’s step-response cycle to clean, standardize, and merge messy CRM datasets. By the end you will have a working agent capable of scoring 0.99 (the maximum grader award) on Task 1 and the structural vocabulary to tackle Tasks 2 and 3.
Section 1: The CRMDataPipelineEnvClient
Theclient.py module exports CRMDataPipelineEnvClient, a typed wrapper around the environment’s REST API. It extends openenv.core.EnvClient and handles request serialisation, response parsing, and connection lifecycle for you. You never call the HTTP endpoints directly.
A
StepResult has three attributes:
.sync() to ensure the underlying connection is closed cleanly at the end of each episode:
CRMDataPipelineEnvClient includes a graceful ImportError fallback for openenv.core. If openenv-core is not installed, the client stubs out EnvClient and StepResult so the file still imports. Always install openenv-core for production use: pip install openenv-core.Section 2: The Episode Loop Pattern
Every agent interaction with the environment follows the same canonical pattern: reset → observe → decide → step → repeat untildone=True or you exceed the step budget.
Section 3: Complete Task 1 Agent
Task 1 (t1) presents a single source table named web_forms containing customer records with inconsistent email casing, mixed date formats, dirty phone strings, and duplicate rows. The full cleaning sequence is:
- Profile the source to get null counts and type info
- Standardize
email→ lowercase and strip whitespace - Standardize
signup_date→ ISO-8601 (YYYY-MM-DD) - Standardize
phone→ digits only (EXTRACT_NUMBERS) or E.164 format - Deduplicate by email (exact match)
- Drop rows with null emails
- Submit
decide_action with t1_agent:
Section 4: Reading the Observation Effectively
CRMPipelineObservation carries every signal your agent needs to decide its next action. Here is how to access each field:
Interpreting feedback strings
Thelast_action_feedback field is the fastest way to understand what the server did. Common patterns:
Section 5: The Full Action Type Reference
Every action is aCRMPipelineAction Pydantic object. Fields not relevant to a given action_type should be left as None (the default). The server serialises actions via model_dump_json(exclude_none=True).
Section 6: LLM-Based Agent Pattern
You can replace the rule-baseddecide_action function with an LLM call to make the agent generalize across unknown data distributions. The pattern below mirrors what inference.py does internally.
Section 7: Task 2 and Task 3 Patterns
Task 2 — Two-source merge
Task 2 requires you to clean bothweb_forms and legacy_db independently, then union them into a single merged_output table and deduplicate.
Task 3 — Three-source enterprise merge with conflict rules
Task 3 adds a third source (salesforce) and requires you to check obs.conflict_rules to understand how the grader expects conflicting column values to be resolved. The legacy_db source uses different column names (contact_email, home_phone, legacy_id) that must be aliased in SQL.
Section 8: Error Handling
Agents should be defensive. The server is lenient about bad actions (it returns a negative reward and an error feedback string rather than crashing), but your agent needs to recover gracefully.Common error patterns and fixes
reward=-0.05 with 'Error:' in feedback
reward=-0.05 with 'Error:' in feedback
The server rejected your action. This usually means:
- Wrong source name: Double-check
obs.available_sources. SQL-created tables (e.g.,web_forms_clean) only appear inavailable_sourcesafter theEXECUTE_SQLthat created them. - Wrong column name: Use
PROFILE_SOURCEfirst to see exact column names. Legacy DB often usescontact_emailinstead ofemail. - Invalid strategy: Confirm the strategy string exactly matches the enum values in
models.py(TO_DATETIME_ISO, notISO_DATE).
done=False after SUBMIT_PIPELINE
done=False after SUBMIT_PIPELINE
The server accepted your submission but returned
done=False. This happens when you call SUBMIT_PIPELINE before completing at least 3 meaningful cleaning steps. The server enforces a minimum pipeline depth to prevent trivially submitting raw data.Check obs.last_action_feedback for a hint like "Pipeline too shallow — apply at least 3 transformations before submitting." Then continue cleaning before retrying SUBMIT_PIPELINE.EXECUTE_SQL returns zero rows
EXECUTE_SQL returns zero rows
Your If the view is empty, revise your SQL and run
WHERE clause is too restrictive or uses wrong column names. Use VIEW_SOURCE after the SQL to inspect the resulting table:EXECUTE_SQL again with a different output_table name. Old table names remain valid in memory — you can overwrite them.Score 0.01 despite correct-looking data
Score 0.01 despite correct-looking data
A score of
0.01 is the grader’s minimum — it means the grader could not match any rows. The most common causes:- You submitted the wrong
final_sourcename (e.g.,web_formsinstead ofmerged_outputfor t2/t3). - Dates are still in
MM/DD/YYYYformat instead ofYYYY-MM-DD— applyTO_DATETIME_ISObefore submitting. - Phone numbers contain non-digit characters — apply
EXTRACT_NUMBERSorPHONE_E164. customer_idvalues contain'???'placeholders — filter them withEXECUTE_SQL.