Skip to main content
This example demonstrates how to integrate Composio tools with Anthropic’s Claude API, including support for prompt caching to improve performance and reduce costs.

Overview

In this example, you’ll learn how to:
  • Initialize Composio with the Anthropic provider
  • Use prompt caching for better performance
  • Handle tool calls with Claude
  • Process multi-turn conversations with tool results

Prerequisites

1

Install dependencies

2

Set up environment variables

Create a .env file with your API keys:

Complete Example

How It Works

1

Initialize with Anthropic Provider

We initialize Composio with the AnthropicProvider, enabling prompt caching with cacheTools: true. This reduces latency and costs for repeated tool definitions.
2

Fetch and Format Tools

The tools are automatically formatted to match Anthropic’s tool calling format, including the proper schema structure.
3

First Message with Tools

We send the initial message to Claude along with the available tools. Claude analyzes the request and decides whether to use any tools.
4

Execute Tool Calls

If Claude decides to use a tool, we extract the tool use blocks and execute them using Composio’s handleToolCalls method.
5

Follow-up Message

We send the tool results back to Claude in a follow-up message, allowing it to generate a final response based on the data.

Expected Output

Key Features

The cacheTools: true option enables Anthropic’s prompt caching feature, which caches tool definitions between requests. This significantly reduces latency and API costs for repeated tool usage.
The example demonstrates how to handle multi-turn conversations where tool results are fed back to Claude for final processing.
Composio automatically converts tool schemas to Anthropic’s expected format, handling all the complexity of tool definition conversion.

Next Steps

LangChain Integration

Build agent workflows with LangChain

File Handling

Work with file attachments in tools