# Agentic RAG

Structure (from the official agentic RAG guide):

1. Query analysis node: the model rewrites or decomposes the user question into retrieval queries.
2. Retrieval node: run the queries against the vector store.
3. Decision: grade the retrieved documents. Good enough -> generate. Not enough -> rewrite the query and retrieve again (bounded; do not loop forever).
4. Generation node: answer from the retrieved context, citing it.

## Rules

- Bound the retrieve-retry loop with a counter in state. Unbounded re-retrieval is the agentic-RAG version of an infinite loop; GRAPH_RECURSION_LIMIT will eventually catch it, but your budget catches it first.
- Grade documents with a cheap model or a rubric, not the big generator. Retrieval grading is a classification task.
- Keep the 2-step RAG as your baseline and eval both on the same dataset. Agentic RAG wins on multi-hop and loses on latency and cost; prove the tradeoff is worth it before shipping.
- Stream with `stream_mode="updates"` so the UI can show "searching..." states per node; token streaming alone hides the retrieval work.