Home/Agentic AI/Tool Execution/Invocation Patterns

Tool Execution & Results

Master invocation patterns, result handling, and error management for reliable AI agents

Invocation 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 request
2
Tool processes
3
Response returned
4
Client continues
Characteristics:
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

DurationReal-time Needed?Recommended Pattern
< 5 secondsNoRequest-Response
< 5 secondsYesStreaming
5-30 secondsNoAsync Polling
5-30 secondsYesStreaming
> 30 secondsAnyWebhook 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