Article·docs.anthropic.com
tool-useanthropicclaudefunction-calling
Anthropic Tool Use
Explore Anthropic's tool use feature, enabling Claude models to interact with external tools and APIs. Define tools with schemas, call them in parallel, and stream results. Enhance Claude's capabilities by integrating it with external services.
intermediate30 min4 steps
The play
- Define a Tool SchemaCreate a JSON schema that describes the inputs your tool expects. This schema will guide Claude in using the tool correctly.
- Call the Tool with ClaudeSend a prompt to Claude that requires the use of your defined tool. Claude will then generate a structured tool call based on the input schema. This is done via the messages API.
- Process the Tool Call ResultAfter Claude generates the tool call, execute the tool with the provided arguments. Then, send the result back to Claude as a new message.
- Receive Claude's ResponseClaude will now generate a final response incorporating the information from your tool. Present this response to the user.
Starter code
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use. Infer this from the user's location."
}
},
"required": ["location"]
}
}Source