Skip to main content

Single Tool Calling

The simplest pattern is calling a single tool. This is useful for straightforward operations like getting weather data or sending an email.

Understanding Single Tool Steps

When using a single tool, you typically need 2 steps:
  1. Step 1: Call the tool and get data
  2. Step 2: Process the data and provide a natural language response

Multiple Tool Calling

For more complex operations, you can chain multiple tools together. This is useful for workflows like getting weather data and sending it via email.

Understanding Multiple Tool Steps

For multiple tools, the steps typically flow like this:
  1. Step 1: Call first tool (e.g., weather)
  2. Step 2: Process first tool’s data
  3. Step 3: Call second tool (e.g., email)
  4. Step 4: Process second tool’s result
  5. Step 5: Provide final summary

Complex Example: Weather + Crypto + Email

Here’s an example of chaining three tools to send both weather and crypto data via email:

Best Practices

When working with tools, follow these guidelines:

Setting Max Steps

  • Single tool: Use 2 steps (call + summary)
  • Multiple tools: Use (2 × number of tools) + 1
  • Complex workflows: Add extra steps if needed for better processing

System Prompts

  • Be specific about the order of operations
  • Include formatting instructions
  • Specify default values (e.g., email subjects)
  • Define error handling preferences

Monitoring and Debugging

Track tool execution and responses using structured logging:
Example debug output:

Error Handling

Implement robust error handling with retries and fallbacks:
This implementation shows:
  • Structured logging of all steps and tool calls
  • Retry logic with exponential backoff
  • Specific error handling for each tool
  • Fallback behaviors (cached data, retry queue)
  • Response validation
  • Detailed error context for debugging

Common Patterns

Here are some common tool calling patterns with practical examples:

Sequential Processing

When one tool’s output is needed for the next tool’s input:

Conditional Branching

When the choice of second tool depends on the first tool’s result:

Data Aggregation

When you need to combine data from multiple tools:

Interactive Processing

When you need multiple interactions with the same tool: