Keep document structure in the retrieval context
Long contracts contained headings spanning multiple pages, alongside tables and diagrams. Fixed-size chunks could separate an answer from the context that explained it. I introduced heading-based parent/child chunks so retrieval could find a relevant passage and retain its surrounding section.
The change improved retrieval-context relevance by approximately 30–40%. For tables and diagrams, I added descriptive metadata in PostgreSQL to complement vector retrieval and connect the answer to supporting evidence.
Make planning and tool execution bounded
I implemented graph nodes, edges, state and routing for new use cases, and extended existing graph paths. Shared state carried the query and retrieved context through planning, tool use and answer preparation.
Planning timeouts, capped retries, exponential backoff and fallback paths bounded failures. Stalled or unsuccessful runs could be handed off through dead-letter handling instead of continuing indefinitely. LangSmith traces supported investigation of divergent plans.
Validate both sides of the response
Input validation, scope checks and prompt-injection checks ran before agent execution; output checks ran before returning a response. Retrieval evaluation used relevance, precision, recall and ranking measures to assess quality.
I also implemented reward-model training and the reinforcement-learning stage of an RLHF pipeline whose resulting model reached production. The final satisfaction score was approximately 75%, assessed against the first three months of operation; this is a final score, not a 75% increase.
Outcomes
- Delivered retrieval and orchestration components processing 1.5 million requests over six months within a field-sales agent serving 75,000 daily active users by implementing and extending workflows across CRM, document and SQL data sources on Azure.
- Improved retrieval-context relevance by approximately 30–40% by replacing fixed-size chunks with heading-based parent/child chunks that preserved context across long contract sections.
- Supported new sales-agent use cases while retaining context across tool calls by implementing LangGraph nodes, edges, shared state and routing, and extending the existing orchestration graph.
- Bounded agent planning and tool-execution failure paths with timeouts, capped retries, exponential backoff and fallbacks by implementing explicit controls and dead-letter handling for stalled or unsuccessful runs.
- Delivered an RLHF-trained model into production by implementing reward-model training and the reinforcement-learning stage using human feedback.
Tradeoffs
Larger parent sections preserve context but can increase the amount of material passed downstream. Reranking and selective context assembly help keep the answer focused. Bounded retries improve predictability, while explicit failure responses are still necessary when a source or tool remains unavailable.