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(user_id="user_123", 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, and returns the raw results in order. 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

composio_anthropic-0.19.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

composio_anthropic-0.19.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file composio_anthropic-0.19.0.tar.gz.

File metadata

  • Download URL: composio_anthropic-0.19.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for composio_anthropic-0.19.0.tar.gz
Algorithm Hash digest
SHA256 9613c717eb75fa6ed7b8edf86e30ca214c535182022a43d721ba6cb22e4099e6
MD5 183189a104db5ce9cc1b0fbd8f58f629
BLAKE2b-256 f78c966932ce81c84038cb61e4992db65922f92dc7ddc528fad1a15532d3c487

See more details on using hashes here.

File details

Details for the file composio_anthropic-0.19.0-py3-none-any.whl.

File metadata

File hashes

Hashes for composio_anthropic-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7690df89030b2397ddff108744b15c129d9107d82df62e70abe95715bd11be34
MD5 f5c9de4b181c4db19b49b445f353735b
BLAKE2b-256 921f22d2d71e2999497d70119627a59372576ee1af2f4c5b17f7e5659a2b9b81

See more details on using hashes here.

Release history Release notifications | RSS feed

0.20.0

2 files

This release

0.19.0 This release

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.1

2 files

0.13.0

2 files

0.12.0

2 files

0.11.6

2 files

0.11.5

2 files

0.11.4

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.10

2 files

0.10.9

2 files

0.10.8

2 files

0.10.7

2 files

0.10.6

2 files

0.10.5

2 files

0.10.4

2 files

0.10.3

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.20

2 files

0.8.19

2 files

0.8.16

2 files

0.8.15

2 files

0.8.14

2 files

0.8.13

2 files

0.8.12

2 files

0.8.11

2 files

0.8.10

2 files

0.8.9

2 files

0.8.8

2 files

0.8.7

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page