Skip to main content
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
  1. Define a Tool Schema
    Create a JSON schema that describes the inputs your tool expects. This schema will guide Claude in using the tool correctly.
  2. Call the Tool with Claude
    Send 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.
  3. Process the Tool Call Result
    After Claude generates the tool call, execute the tool with the provided arguments. Then, send the result back to Claude as a new message.
  4. Receive Claude's Response
    Claude 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
Anthropic Tool Use — Action Pack