Designing retrieval and code review for a data-engineering agent
I work on Purgo AI’s data-engineering agent, a multi-agent LangGraph system that turns a data team’s ticket into PySpark, SQL and dbt code. I work on the whole agent, from retrieval and context engineering to prompts, orchestration and evals, and I measure each change on real tickets.
Retrieval picks the few tables the LLM sees out of hundreds
Code review
Ticket- 1Analyze the ticket (the team’s)
- 2Find candidate tables (I built this stage)
- 3Follow dbt lineage (I built this stage)
- 4Check against the warehouse schema (I built this stage)
- 5Rank candidates with an LLM (I reworked this stage)
- 6Draft a design (I reworked this stage)
- 7Write and review the code (I reworked this stage)
- Checks and the recovery path in the review loop, which lints and repairs the code before it ships (stage 7)
The agent’s stages: I built, I reworked, The team’s
I designed the agent’s retrieval: the pipeline that picks the few tables the LLM sees out of hundreds. The hard case is a table the ticket needs but never mentions. Search ranks it low, the reranker drops it, and the agent writes code against the wrong table. To fix that, I parse the SQL of the dbt models the ticket does mention, follow their lineage upstream and keep those tables in context no matter how the reranker scores them. I chose the design with an ablation of four variants on about a hundred real tickets.
I also set the context budget across tables, attachments and repo code, moved two stages to a smaller, cheaper model with no loss in recall, and built several of the review loop’s checks and the recovery path for when every draft fails.
Read the write-up: Designing retrieval and code review for a data-engineering agent, 9 min


