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-4-6",
    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":
    tool_use_blocks = [block for block in response.content if block.type == "tool_use"]
    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": tool_use_blocks[i].id, "content": json.dumps(result)}
            for i, result in enumerate(results)
        ]
    })
    response = client.messages.create(
        model="claude-opus-4-6",
        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 from the response, executes the matching Composio tools through the supplied session, and returns the raw results in 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.

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

Links

Release files for composio-anthropic 0.21.1

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.21.1
File Size Uploaded
composio_anthropic-0.21.1.tar.gz 4.1 kB Details

Built distribution (wheel)

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

Total release size: 8.4 kB

Release files / composio_anthropic-0.21.1.tar.gz

Download URL composio_anthropic-0.21.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5b52a23238ad6f7391cd2486b6e9f67dd0d304f8a63069a183e80852fc3c6e1e
BLAKE2b-256 checksum
How to use checksums
1f52a51da5540810ca889857ac94e5543360aef80279af5704b5133ff9a4d2a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL composio_anthropic-0.21.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5d3a989429305968f9dbdabff973027d569b4840932b8e2bfeef1ec7cf7cda4
BLAKE2b-256 checksum
How to use checksums
41e5ac1d435602f23107da631abfcc308b6ab35618ff28ffe0db5cad8b473c89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.24.0

2 release files

0.23.0

2 release files

0.22.0

2 release files

This release

0.21.1 This release

2 release files

0.21.0

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.1

2 release files

0.12.0

2 release files

0.11.6

2 release files

0.11.5

2 release files

0.11.4

2 release files

0.11.3

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.9

2 release files

0.10.8

2 release files

0.10.7

2 release files

0.10.6

2 release files

0.10.5

2 release files

0.10.4

2 release files

0.10.3

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.19

2 release files

0.8.16

2 release files

0.8.15

2 release files

0.8.14

2 release files

0.8.13

2 release files

0.8.12

2 release files

0.8.11

2 release files

0.8.10

2 release files

0.8.9

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

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