How it works
The pipeline usesAgenticRouter (from components/agentic_router.py) as the central decision-maker. The router is a ChatGroq LLM that returns structured JSON decisions at each step.
Decision loop
Router decisions
TheAgenticRouter.route() method receives:
query: the original user questionhas_documents: whether documents have already been retrievedcurrent_answer: the current draft answer (if any)iteration: current iteration number (1-indexed)max_iterations: the hard loop limit
{"action": "search|reflect|generate", "reasoning": "..."}.
When iteration >= max_iterations, the router automatically returns "generate" regardless of quality — this is the safety mechanism that prevents infinite loops.
State machine
- search
- reflect
- generate
Called when no documents have been retrieved yet, or when reflection identified information gaps requiring additional retrieval.
Pipeline implementation
The agentic RAG pipeline orchestrates the router, retriever, and generator:src/vectordb/langchain/agentic_rag/base.py
Configuration
When to use it
- Complex multi-hop questions where the answer requires combining information from multiple retrieval passes
- High-stakes applications where answer completeness and grounding must be verified before delivery
- Workflows where single-pass retrieval and generation consistently underperforms on hard questions
When not to use it
Tradeoffs
Settings to tune first
integer
default:"3"
Start with 2; increase only if quality does not converge at lower values.Without a hard loop cap, the router can cycle indefinitely. Always set a finite limit.
float
default:"0.0"
Use 0.0 for routing (deterministic decisions); 0.7 for answer generation (creative).
string
default:"llama-3.3-70b-versatile"
The routing template directly determines how well the LLM navigates the state machine.Recommended:
llama-3.3-70b-versatile or gpt-4Router prompt template
TheAgenticRouter.ROUTING_TEMPLATE is a structured prompt that includes the current query, has_documents flag, current_answer, and iteration count. The LLM must return a JSON object with "action" and "reasoning" keys.
ValueError for fast debugging.
Example execution trace
Common pitfalls
Backends supported
Chroma, Milvus, Pinecone, Qdrant, Weaviate.Next steps
Query enhancement
Use query enhancement for lighter-weight recall improvements without the full agentic loop
Reranking
Use reranking for faster single-pass pipelines sufficient for simpler queries
Components
Explore the AgenticRouter and QueryEnhancer components in detail
Semantic search
Start with baseline semantic search before adding agentic patterns