Skip to main content

composio-anthropic

Adapts Composio tools to the Claude Messages API tool format and executes the tool calls Claude returns.

Installation

pip install composio composio-anthropic anthropic

Set COMPOSIO_API_KEY (create one at https://dashboard.composio.dev/settings) and ANTHROPIC_API_KEY in your environment.

Quickstart

AnthropicProvider is non-agentic: Claude returns tool_use blocks, handle_tool_calls executes them, and you send the results back as tool_result blocks.

import json
import anthropic
from composio import Composio
from composio_anthropic import AnthropicProvider

composio = Composio(provider=AnthropicProvider())
client = anthropic.Anthropic()

# Create a session for your user
session = composio.create(user_id="user_123")
tools = session.tools()

messages = [
    {"role": "user", "content": "Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'"}
]

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=4096,
    tools=tools,
    messages=messages,
)

# Agentic loop: keep executing tool calls until the model responds with text
while response.stop_reason == "tool_use":
    # Results retain each tool_use ID; Python still needs explicit content blocks.
    results = composio.provider.handle_tool_calls(session=session, response=response)
    messages.append({"role": "assistant", "content": response.content})
    messages.append({
        "role": "user",
        "content": [
            {
                "type": "tool_result",
                "tool_use_id": result["tool_use_id"],
                "content": json.dumps(result),
                "is_error": not result["successful"],
            }
            for result in results
        ]
    })
    response = client.messages.create(
        model="claude-opus-5-5",
        max_tokens=4096,
        tools=tools,
        messages=messages,
    )

# Print final response
for block in response.content:
    if block.type == "text":
        print(block.text)

handle_tool_calls extracts every tool_use block, executes the matching Composio tools through the supplied session, and returns execution dictionaries in tool-use order. Pass user_id instead for tools fetched with tools.get(). Claude occasionally emits tool input as a JSON string instead of an object; the provider normalizes this before execution.

Execution contracts

execute_tool_call(session=session, tool_call=block) returns one AnthropicToolExecutionResponse; handle_tool_calls(session=session, response=response) returns a list. Import both the provider and the response type from composio_anthropic.

Each result contains tool_use_id, data, error, and successful. Session-backed results also retain result_type, log_id, and instant_charge when returned. Check result["successful"] explicitly. A failed execution can have an empty or None error, and a log ID is only for correlation.

These are Python dictionaries, not Anthropic tool_result blocks. Serialize with json.dumps(result), pair each block with result["tool_use_id"], and set is_error from not result["successful"], as above. Existing code that pairs the ordered results with the original tool_use blocks still works. TypeScript's handleToolCalls instead returns ready-to-append messages; don't use that contract in Python.

On older provider releases without tool_use_id, keep pairing the ordered results with the original tool_use blocks, as in the web guide. The correlation field is additive; the helper still returns execution dictionaries rather than native messages.

Entry point Arguments Result and outcome check
Python session.execute tool_slug=..., arguments={...} Pydantic model; result.result_type == "completed". Use model_dump(mode="json") or model_dump_json() for serialization. No model call ID.
Python composio.tools.execute slug=..., arguments={...}, user_id=... ToolExecutionResponse dictionary; result["successful"].
Python after_execute modifier (tool, toolkit, response) Receives and returns a ToolExecutionResponse dictionary; check response["successful"], not an attribute.
Python Anthropic helpers session=... or user_id=...; tool_call=... or response=... Correlated execution dictionaries; result["successful"].

Session adapters derive successful from result_type == "completed"; "failed" and "blocked" are not successful. session.execute itself doesn't run session.tools(modifiers=...) callbacks. Direct-execution modifiers can't be passed alongside a session to a provider helper.

Transport, authentication, and input errors can raise instead of returning a tool result. Handle credential/connection recovery separately from an ordinary returned failure. If a batch raises, earlier calls may already have executed. Don't replay the batch blindly. The execution status, an empty error, or a log ID alone doesn't establish a provider-side side effect; inspect the tool-specific data. Retry and idempotency policy stays in your application.

Building on the Claude Agent SDK instead of the Messages API? Use composio-claude-agent-sdk.

Metadata

Release files for composio-anthropic 0.35.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for composio-anthropic 0.35.0
File Size Uploaded Provenance Actions
composio_anthropic-0.35.0.tar.gz 8.4 kB With provenance Details for composio_anthropic-0.35.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for composio-anthropic 0.35.0
File Interpreter ABI Platform Actions
composio_anthropic-0.35.0-py3-none-any.whl Python 3 none any Details for composio_anthropic-0.35.0-py3-none-any.whl

Total release size: 15.1 kB

Release files / composio_anthropic-0.35.0.tar.gz

Download URL composio_anthropic-0.35.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05a2a3aee75243deac8e3fe6e3bf93f877810aa9a9b295f9bbf7c42ec4ed4cfe
BLAKE2b-256 checksum
How to use checksums
68c50b16e7505827bbfbcb1dcb0f188dd83a28fe962ce8f2fbc26833064e4347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / composio_anthropic-0.35.0-py3-none-any.whl

Download URL composio_anthropic-0.35.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb4f77f02f00bca5cb8748a8ef28961df56ec67e7b0a5c6f027d20397e623b2e
BLAKE2b-256 checksum
How to use checksums
6701b58d93d431c80049b8abe8f77a2f5f0a4715bc8190f7f2c2ef1dba4689a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for composio-anthropic 0.35.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for composio_anthropic-0.35.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.35.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page