Lesson 2 of 20

Agentic Design Patterns

Tool Use Pattern

3 min read

Tool use transforms AI agents from knowledge systems into action-takers. By connecting to external tools, agents can search the web, execute code, query databases, and interact with APIs.

How Tool Use Works

Modern LLMs are trained to recognize when they need external tools and how to call them:

# Defining tools for an agent
tools = [
    {
        "name": "web_search",
        "description": "Search the web for current information",
        "parameters": {
            "query": {"type": "string", "description": "Search query"}
        }
    },
    {
        "name": "calculator",
        "description": "Perform mathematical calculations",
        "parameters": {
            "expression": {"type": "string", "description": "Math expression"}
        }
    }
]

# Agent decides which tool to use
response = llm.generate(
    prompt=user_query,
    tools=tools,
    tool_choice="auto"  # Let the model decide
)

The Tool Calling Flow

  1. User request → Agent receives task
  2. Tool selection → Agent decides if/which tool to use
  3. Parameter extraction → Agent formats the tool call
  4. Execution → System runs the tool
  5. Result integration → Agent incorporates result into response

Common Tool Categories

Category Examples Use Cases
Information Web search, Wikipedia, news APIs Research, fact-checking
Computation Calculator, code interpreter Math, data analysis
Data SQL queries, file operations Business intelligence
Communication Email, Slack, calendar Automation workflows
External Services Weather, maps, translation Real-world integration

MCP: The New Standard

The Model Context Protocol (MCP), now supported by ChatGPT, Gemini, and Copilot, provides a standardized way to connect tools:

// MCP server example
const server = new MCPServer({
  tools: [{
    name: "get_customer",
    description: "Fetch customer data by ID",
    inputSchema: { customerId: "string" }
  }]
});

2025 Update: Over 10,000 MCP servers are now active, with adoption across major AI platforms.

Best Practices

  • Clear descriptions: Help the model understand when to use each tool
  • Validate inputs: Check parameters before execution
  • Handle failures: Tools can timeout or return errors
  • Limit scope: Only expose necessary capabilities

Next, we'll learn how agents break down complex tasks through planning. :::

Quiz

Module 1: Agentic Design Patterns

Take Quiz