The complete execution path showing how agents process queries, make decisions, call tools, manage state, and iterate through Agentic RAG reflection cycles
π―
User Query Received
Agent receives input from user (question, task, or command)
β
π
Initialize State
Create state object with query, system instructions, empty message history, and tool definitions
π State Contents:
Query text, system prompt, messages[], tool_calls[], intermediate_results[], current_step
β
π§
Check Memory (Optional)
Retrieve relevant context from short-term (session) or long-term (cross-session) memory if applicable
β
π
Prepare Messages
Construct message array: system prompt + memory context + conversation history + current query
β
π€
Call LLM
Send messages + available tools to language model for reasoning and response generation
β
π
Parse LLM Response
Extract text response, function calls (if any), and any structured outputs
β
β
Tools Needed?
Did LLM request function calls?
β YES - TOOL EXECUTION PATH
π οΈ
Extract Tool Calls
Parse function name + arguments from LLM response
β
β
Validate Arguments
Check required fields, types, formats using schemas
β
β‘
Execute Tool
Call API, query database, run search, or perform computation
β
π
Process Results
Format tool output for next LLM call
β
π
Update State
Add tool results to message history, increment step counter
β
π
More Tools?
Need additional tools or final response?
If more tools needed, loop back to "Call LLM"
Otherwise, proceed to final response
β NO - DIRECT RESPONSE PATH
π
Extract Text Response
LLM provided complete answer without needing tools
β
β¨
Validate Output
Check for structured output compliance (if Pydantic schema provided)
β
πΎ
Update Memory
Store conversation in short-term memory for session continuity
β
β
Return Final Response
Send answer back to user
β
π
Task Complete
Agent returns final synthesized response to user
π Agentic RAG Reflection & Retry Loop
When does this activate? When using retrieval tools (vector search, web search, database queries), Agentic RAG adds an evaluationβreflectionβretry cycle to improve result quality.
1
π
Retrieve
Execute search query, get initial results from vector DB or web
2
π€
Generate
LLM creates answer based on retrieved context
3
βοΈ
Evaluate
Judge quality: Is answer complete? Are sources relevant?
4
π
Decide
Good enough? Return. Needs work? Reflect & retry
β²If quality insufficient, loop back with improved queryβ²
Key Difference from Traditional RAG: Traditional RAG is "retrieve once, generate once." Agentic RAG actively evaluates output quality, reflects on what's missing, reformulates queries, and retries until satisfactoryβlike a researcher iterating on a literature review.
β οΈ Error Handling & Resilience
π
API Failure
Retry with backoff, use fallback tool, or inform user gracefully
β
Validation Error
Request corrected output from LLM with error details
β±οΈ
Timeout
Cancel long-running tool, return partial results or error message
π
Auth Failure
Prompt user to reconnect or use alternative data source