| title | Step 2: Add Tools |
|---|---|
| description | Give your agent the ability to call functions and interact with the world. |
| zone_pivot_groups | programming-languages |
| author | eavanvalkenburg |
| ms.topic | tutorial |
| ms.author | edvan |
| ms.date | 07/01/2026 |
| ms.service | agent-framework |
Tools let your agent call custom functions — like fetching weather data, querying a database, or calling an API.
:::zone pivot="programming-language-csharp"
Define a tool as any method with a [Description] attribute:
using System.ComponentModel;
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
=> $"The weather in {location} is cloudy with a high of 15°C.";Create an agent with the tool:
using System;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("Set AZURE_OPENAI_ENDPOINT");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
AIAgent agent = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())
.AsAIAgent(
model: deploymentName,
instructions: "You are a helpful assistant.",
tools: [AIFunctionFactory.Create(GetWeather)]);Warning
DefaultAzureCredential is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
The agent will automatically call your tool when relevant:
Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?"));Tip
See here for a full runnable sample application.
:::zone-end
:::zone pivot="programming-language-python"
Define a tool with the @tool decorator:
:::code language="python" source="~/../agent-framework-code/python/samples/01-get-started/02_add_tools.py" id="define_tool" highlight="3":::
Create an agent with the tool:
:::code language="python" source="~/../agent-framework-code/python/samples/01-get-started/02_add_tools.py" id="create_agent_with_tools" highlight="4":::
Tip
See the full sample for the complete runnable file.
:::zone-end
:::zone pivot="programming-language-go"
Define a tool using functool:
import (
"context"
"fmt"
"github.com/microsoft/agent-framework-go/tool"
"github.com/microsoft/agent-framework-go/tool/functool"
)
var weatherTool = functool.MustNew(functool.Config{
Name: "weather",
Description: "Get the current weather for a given location",
}, func(_ context.Context, location string) (string, error) {
return fmt.Sprintf("The weather in %s is cloudy with a high of 15°C.", location), nil
})Create an agent with the tool:
a := foundryprovider.NewAgent(
endpoint,
token,
foundryprovider.ModelDeployment(model),
foundryprovider.AgentConfig{
Instructions: "You are a helpful assistant",
Config: agent.Config{
Tools: []tool.Tool{weatherTool},
},
},
)The agent will automatically call your tool when relevant:
resp, err := a.RunText(ctx, "What is the weather like in Amsterdam?").Collect()
fmt.Println(resp, err)Tip
See the full sample for the complete runnable file.
:::zone-end
[!div class="nextstepaction"] Step 3: Multi-Turn Conversations
Go deeper:
- Tools overview — learn about all available tool types
- Function tools — advanced function tool patterns
- Tool approval — human-in-the-loop for tool calls