- The Claude Messages API, where you run the tool-call loop yourself.
- The Claude Agent SDK, where the SDK runs the loop and Composio tools are exposed as an in-process MCP server.
- Messages API
- Claude Agent SDK
The
AnthropicProvider transforms Composio tools into the format the Claude Messages API expects, then executes the tool calls Claude requests and shapes the results back into Messages API content blocks.1
Install
Install
- Python
- TypeScript
2
Configure API Keys
Configure API Keys
Set
COMPOSIO_API_KEY with your API key from Settings and ANTHROPIC_API_KEY with your Anthropic API key..env
3
Create session and run
Create session and run
Passing a session to
handle_tool_calls / handleToolCalls requires composio newer than 0.19.0 (Python) or @composio/core ≥ 0.17.0 with @composio/anthropic ≥ 0.11.0 (TypeScript). On earlier versions, execute session tools with session.execute().- Python
- TypeScript
Pass the session to
handleToolCalls / handle_tool_calls when the model received tools from session.tools(). The helper preserves Anthropic input normalization and restored schema aliases before executing every call through that session. For tools fetched via tools.get, pass the user ID instead.Provider specifics
A few things are specific to the Anthropic provider:- Tool caching. Pass
cacheTools: trueto the constructor (new AnthropicProvider({ cacheTools: true })) to attach Anthropic’s ephemeralcache_controlto the last tool definition, which caches the whole tool list. This lets Claude reuse cached tool schemas across requests and can cut prompt cost when you send the same large tool set on every turn. Anthropic allows at most 4cache_controlbreakpoints per request, so tool-result blocks are not marked, and lists merged from severalwrapToolscalls each keep a breakpoint on their last tool. handleToolCallsreturns Messages API content, not raw strings. TypeScript returns a ready-to-appendusermessage oftool_resultblocks. Python returns raw results in model-call order, which the sample wraps intotool_resultblocks.- String-encoded tool inputs are handled for you. Claude occasionally emits a tool’s
inputas a JSON string instead of an object. The provider normalizes it before both direct and session execution. cacheToolsonly. The constructor takes no other options. There is no agentic execution in this provider; you run the loop (Messages API) or hand the loop to the Claude Agent SDK (Agent SDK tab).- Python tool caching. Pass
cache_tools=Trueto the constructor (AnthropicProvider(cache_tools=True)) to attach Anthropic’s ephemeralcache_controlto the tool definitions, ascacheToolsdoes in TypeScript.wrap_toolsmarks only the last tool, which caches the whole tool list within Anthropic’s limit of 4 breakpoints per request. Tool results are not marked.