Handling Execution Results
What you'll learn: How to process the output from executed tools and feed that information back into your agent's decision-making flow.
Why Tool Results Matter
When your agent executes a tool (like searching the web or querying a database), it receives raw output—but that's only half the story. The agent needs to interpret this result and decide what to do next. Think of it like asking someone to check the weather: they don't just read you the raw JSON response from a weather API—they tell you "It's going to rain, bring an umbrella."
The Result Processing Pipeline
After a tool executes, you need to:
- Capture the raw output – Store whatever the tool returned (string, JSON, error message, etc.)
- Validate and sanitize – Check for errors, timeouts, or malformed data
- Format for the agent – Transform the result into a format your LLM can understand
- Update agent context – Add the result to the conversation history or working memory
- Trigger next iteration – Pass control back to the decision module with the new information
Practical Processing
Results should be structured observations. Instead of dumping raw data, you might format it as:
- "Tool: search_web | Status: success | Found: 3 articles about..."
- "Tool: calculate | Status: success | Result: 42"
- "Tool: database_query | Status: error | Message: Connection timeout"
This structured format helps the LLM reason about what happened and what to do next. The result becomes the new observation that feeds into the next perception-reasoning-action cycle.
Key Takeaway: Handling execution results means transforming raw tool outputs into structured observations that your agent can interpret, then injecting them back into the agent's context to drive the next decision.