Tool Execution & Results
Master invocation patterns, result handling, and error management for reliable AI agents
Your Progress
0 / 5 completedInvocation Patterns: How to Call Tools
Not all tool calls are created equal. The invocation pattern you choose determines latency, resource usage, and user experience. Understanding these patterns is crucial for building responsive, scalable AI agents.
Let's explore the four fundamental patterns and when to use each one.
Interactive: Pattern Comparison
Select a pattern to explore its implementation, flow, and trade-offs
Pattern:
Classic synchronous call pattern
Best for:Quick operations, data retrieval
async function callTool() {
const response = await tool.invoke({
name: 'get_weather',
parameters: {
location: 'Tokyo',
units: 'celsius'
}
})
return response.data
}Execution Flow:
1
Client sends request2
Tool processes3
Response returned4
Client continuesCharacteristics:
Timing:
Synchronous - waits for completion
Ideal Duration:
Operations under 5 seconds
✓ Advantages
- •Simple to implement
- •Easy to reason about
- •Immediate feedback
⚠ Limitations
- •Blocks on long operations
- •No progress updates
- •Timeout risk
Pattern Selection Guide
| Duration | Real-time Needed? | Recommended Pattern |
|---|---|---|
| < 5 seconds | No | Request-Response |
| < 5 seconds | Yes | Streaming |
| 5-30 seconds | No | Async Polling |
| 5-30 seconds | Yes | Streaming |
| > 30 seconds | Any | Webhook Callback |
Real-World Examples
💬
Request-Response
Weather lookups, currency conversion, simple calculations
Use when: Instant results expected
🔄
Async Polling
Document analysis, image processing, report generation
Use when: Operation takes 10-60s
🪝
Webhook Callback
Video transcoding, large-scale data processing, ML training
Use when: Operation takes minutes/hours
🌊
Streaming
LLM text generation, live stock prices, real-time logs
Use when: Incremental results valuable