This sample demonstrates how to use function tools with Anthropic Claude agents, allowing agents to call custom functions to retrieve information.
- Creating function tools using AIFunctionFactory
- Passing function tools to an Anthropic Claude agent
- Running agents with function tools (text output)
- Running agents with function tools (streaming output)
- Managing agent lifecycle
Before you begin, ensure you have the following prerequisites:
- .NET 8.0 SDK or later
- Anthropic API key configured
Note: This sample uses Anthropic Claude models. For more information, see Anthropic documentation.
Set the following environment variables:
$env:ANTHROPIC_API_KEY="your-anthropic-api-key" # Replace with your Anthropic API key
$env:ANTHROPIC_CHAT_MODEL_NAME="your-anthropic-model" # Replace with your Anthropic modelNavigate to the Anthropic sample directory and run:
cd dotnet\samples\02-agents\AgentProviders\anthropic
dotnet run --project .\Agent_Anthropic_Step03_UsingFunctionToolsThe sample will:
- Create an agent named "WeatherAssistant" with a GetWeather function tool
- Run the agent with a text prompt asking about weather
- The agent will invoke the GetWeather function tool to retrieve weather information
- Run the agent again with streaming to display the response as it's generated
- Clean up resources by deleting the agent