AI Agents for Beginners - 4. Tool Use Design Pattern
How AI agents use tools via function calling — building blocks, tool schemas, approval modes, and practical examples with Microsoft Agent Framework and Azure AI Agent Service.
June 8, 2026
AI Agents for Beginners - 4. Tool Use Design Pattern
This article summarizes Lesson 04 of Microsoft's AI Agents for Beginners course.
What is the Tool Use Design Pattern?
The Tool Use Design Pattern allows an LLM to interact with external tools to achieve specific goals.
Tools are executable code for an agent, ranging from simple functions (calculators) to third-party API calls (stock quotes, weather forecasts).
Tools are executable code for an agent, ranging from simple functions (calculators) to third-party API calls (stock quotes, weather forecasts).
Without tools, LLMs can only generate text. Adding tools empowers agents to act in the real world by responding to model-generated function calls.
Use Cases
The Tool Use Design Pattern applies to various scenarios requiring dynamic interaction with external systems:
| Use Case | Description | Examples |
|---|---|---|
| Dynamic Information Retrieval | Retrieve up-to-date data from external APIs or databases | SQLite data analysis, stock prices, weather info |
| Code Execution | Execute code or scripts to solve math problems, generate reports | Python code execution, simulations |
| Workflow Automation | Automate repetitive, multi-step workflows | Email services, data pipelines |
| Customer Support | Integrate with CRMs, ticketing platforms, knowledge bases | Automated resolution of user inquiries |
| Content Generation | Integrate grammar checkers, text summarizers, etc. | Support content creation and editing |
Building Blocks
Core building blocks required to implement the Tool Use Design Pattern:
| Building Block | Description |
|---|---|
| Function/Tool Schemas | Detailed schemas defining tool names, purposes, parameters, and outputs. Helps the LLM understand available tools and generate valid requests |
| Function Execution Logic | Logic that determines whether and how to invoke tools based on user intent and conversation context |
| Message Handling System | Component managing conversation flow across user inputs, LLM responses, tool calls, and tool outputs |
| Tool Integration Framework | Infrastructure connecting agents from simple functions to complex external services |
| Error Handling & Validation | Handles tool execution failures, parameter validation, and unexpected responses |
| State Management | Tracks conversation context, prior tool interactions, and persistent data to ensure multi-turn consistency |
Function/Tool Calling
Function Calling is the core mechanism through which LLMs interact with tools.
Its implementation requires three components:
Its implementation requires three components:
1. Initialize an LLM
Initialize an LLM that supports function calling. Azure OpenAI supports this:
init_llm.pypython
2. Create a Function Schema
Define the JSON schema to pass to the LLM. The LLM references this schema to select the appropriate function and generate arguments:
function_schema.pypython
The LLM returns which function to call with which arguments, rather than the final answer.
3. Execute the Function
Execute the selected function and pass the result back to the LLM to generate the final response:
function_execute.pypython
Function Calling FlowMermaidzenuml title Function Calling Flow User->LLM: What time is it in San Francisco? LLM->LLM: select get_current_time from schema LLM->App: tool_call: get_current_time(location=San Francisco) App->Function: get_current_time("San Francisco") Function->App: {"current_time": "09:24 AM"} App->LLM: tool result added to messages LLM->User: The current time in San Francisco is 09:24 AM
Tool Use with Microsoft Agent Framework
MAF significantly simplifies tool definitions with the
Docstrings become tool descriptions, and type annotations serve as parameter schemas that are automatically passed to the LLM.
@tool decorator.Docstrings become tool descriptions, and type annotations serve as parameter schemas that are automatically passed to the LLM.
Defining Tools
maf_tools.pypython
Using Multiple Tools
When multiple tools are registered with an agent, the LLM autonomously selects and invokes them as needed:
maf_multi_tools.pypython
Structured Output with Tools
By specifying a Pydantic model in
response_format, you can receive tool results as structured JSON:maf_structured_tools.pypython
Tool Approval Patterns
The
approval_mode parameter controls whether human approval is required for each tool call:| Mode | Behavior | Use Case |
|---|---|---|
"never_require" | Automatic execution — no user confirmation required | Read-only queries, functions without side effects |
"always_require" | Requires user approval on every call | Functions with side effects such as payments or reservations |
For tools with side effects, always use
"always_require" to maintain a Human-in-the-loop:maf_approval.pypython
Tool Approval FlowMermaidflowchart TD Agent["Agent\nDecides tool call"] Agent --> Check{approval_mode?} Check -->|"never_require"| AutoRun["Automatic execution\n(Query, calculation, etc.)"] Check -->|"always_require"| HumanApproval["Request user approval"] HumanApproval --> Approved{Approved?} Approved -->|Yes| Execute["Execute tool"] Approved -->|No| Cancel["Cancel call"] AutoRun --> Result["Result → LLM"] Execute --> Result
Tool Use with Azure AI Agent Service
Azure AI Agent Service automatically handles tools on the server side.
You can combine multiple tools using
You can combine multiple tools using
ToolSet and take advantage of pre-built tools such as FunctionTool and CodeInterpreterTool.The provided tools fall into two categories:
| Category | Tools |
|---|---|
| Knowledge Tools | Grounding with Bing Search, File Search, Azure AI Search |
| Action Tools | Function Calling, Code Interpreter, OpenAPI tools, Azure Functions |
azure_ai_toolset.pypython
The LLM examines the
toolset and autonomously selects the appropriate option between the custom function (fetch_sales_data_using_sqlite_query) and CodeInterpreterTool based on the user's request.Security Considerations
When an LLM dynamically generates SQL, security risks such as SQL injection arise.
These risks can be effectively mitigated using the following principles:
These risks can be effectively mitigated using the following principles:
- Read-only Access — Grant only SELECT permissions to the DB (block INSERT/UPDATE/DELETE)
- Isolated Environment — Use a read-only data warehouse separated from production systems
- Parameter Validation — Validate and sanitize inputs before executing tools
Summary
Lesson 04 SummaryMermaidflowchart LR Root["Tool Use\nDesign Pattern"] Root --> How["How It Works"] Root --> MAF["Microsoft Agent\nFramework"] Root --> AAAS["Azure AI\nAgent Service"] Root --> Safety["Safety"] How --> H1["Function Schema"] How --> H2["LLM selects tool"] How --> H3["Execute & return"] MAF --> M1["@tool decorator"] MAF --> M2["Multiple tools"] MAF --> M3["approval_mode"] AAAS --> A1["ToolSet"] AAAS --> A2["Knowledge Tools"] AAAS --> A3["Action Tools"] Safety --> S1["Read-only DB"] Safety --> S2["Human-in-the-loop"]
- The Tool Use Design Pattern empowers LLMs with the ability to take real-world actions through external tools
- The core of Function Calling is the Define Schema → LLM selects function → Execute → Return results to LLM cycle
- Easily convert Python functions into tools using the @tool decorator, and maintain human oversight with
approval_mode - For tools with side effects, always use
"always_require"to guarantee a Human-in-the-loop