The RAG subagent
The RAG subagent owns one job: answer policy questions using only retrieved policy chunks. It never invents coverage details. If the chunks do not answer the question, it says so and recommends escalation. This behavior comes from a strict system prompt and a deterministic retrieval call, not from model intuition.
How the RAG subagent answers a policy question
Query in, grounded answer out, citations attached.
POLICY_PROMPT = '''You are the policy agent. Answer the user's question using ONLY the
retrieved policy excerpts below. If the excerpts do not answer the question, say so
and recommend escalation.
User question:
{user_input}
Retrieved policy excerpts:
{context}
Write a concise, friendly answer. Cite sources inline like [source: filename].
'''The prompt locks the model into the retrieved context. "ONLY the retrieved policy excerpts" is the hard rule. The inline citation format is what lets the UI render source links next to claims the model makes.
async def policy_agent_node(state: ClaimState) -> Dict[str, Any]:
query = state.get('user_input', '')
hits = search_policies(query, k=4)
if hits:
context = '\n\n'.join(
f"[source: {h['source']}]\n{h['content']}" for h in hits
)
else:
context = '(no policy documents indexed yet)'
provider = get_llm_provider()
answer = await provider.generate_text(
POLICY_PROMPT.format(user_input=query, context=context),
max_tokens=500,
temperature=0.2,
)
citations = sorted({h['source'] for h in hits})
return {'retrieved_docs': hits, 'answer': answer, 'citations': citations}Temperature 0.2 keeps the subagent close to the source material. Retrieval returns at most four chunks, which fits comfortably in the context window and keeps prompts cheap. The citations set is deduped so the UI shows each source once even if multiple chunks came from the same PDF.
Quiz: Quiz
Loading practice…