Designing Simple Tool Interfaces › The Tool Use Workflow

Michael BrenndoerferJune 25, 20253 min read
AI Agent HandbookAll chapters
Part 5 of 15Tool Use - Extending the Agent's Abilities
Chapter 13Designing Simple Tool Interfaces › The Tool Use Workflow
Reading section 4 of 12 · The Tool Use Workflow · 3 minSection 4 of 12 · 3 min

Section 4 of 12 · 3 min read

Designing Simple Tool Interfaces › The Tool Use WorkflowSection view · Sections in this chapter4 / 12 ↓
Reading tools Notes & comments
Notes & comments

Now let's walk through the complete workflow of how an agent uses a tool. We'll break it down into clear steps:

Step 1: Receive User Input

The user asks a question:

Code
CollapseExpand
User: What's the weather like in Tokyo right now?

Step 2: Decide Whether to Use a Tool

The agent analyzes the question and determines whether it needs a tool. This is where the agent's reasoning comes in. It might think:

Code
CollapseExpand
This question asks about current weather in Tokyo. I don't have access to 
real-time weather data, but I have a get_weather tool that can retrieve 
this information. I should use that tool.

How does the agent make this decision? We can prompt it to consider whether it needs external information:

PythonIn [5]
CollapseExpand
system_prompt = """
You are a helpful assistant with access to tools.

When a user asks a question, first determine if you need to use a tool:
- If the question requires current information (weather, news, stock prices), use a tool
- If the question requires precise calculations, use a tool
- If the question requires taking an action (sending email, updating records), use a tool
- If you can answer from your general knowledge, respond directly

Available tools:
{tool_descriptions}
"""

Step 3: Select the Appropriate Tool

If the agent decides it needs a tool, it must choose which one. With our weather example, this is straightforward since we only have one relevant tool. But imagine the agent has access to:

  • get_weather(city): Get current weather
  • get_forecast(city, days): Get weather forecast
  • calculate(expression): Perform calculations
  • search_web(query): Search the internet

The agent needs to match the user's intent to the right tool. For "What's the weather like in Tokyo right now?", it should choose get_weather, not get_forecast.

Step 4: Extract Parameters

Once the agent has selected a tool, it needs to extract the required parameters from the user's question. For our weather example:

  • Question: "What's the weather like in Tokyo right now?"
  • Tool: get_weather
  • Required parameter: city
  • Extracted value: "Tokyo"

The agent uses its language understanding to identify that "Tokyo" is the city the user is asking about.

Step 5: Call the Tool

Now the agent calls the tool with the extracted parameters:

PythonIn [12]
CollapseExpand
result = tool_registry["get_weather"](city="Tokyo")
## Returns: {"city": "Tokyo", "temperature": 72, "conditions": "partly cloudy", "humidity": 65}

Step 6: Interpret the Result

The agent receives the tool's output and needs to incorporate it into a natural response:

Code
CollapseExpand
Tool output: {"city": "Tokyo", "temperature": 72, "conditions": "partly cloudy", "humidity": 65}

Agent response: "In Tokyo right now, it's 72°F and partly cloudy with 65% humidity."

The agent translates the structured data into natural language that answers the user's question.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy