Skip to main content

Use Composio to get an array of tools with your Anthropic LLMs.

Project description

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

Project details


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.18.1.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.18.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for composio_anthropic-0.18.1.tar.gz
Algorithm Hash digest
SHA256 467029421ec022f97930919052469abd14e15c50622c66396331873d084e5d5d
MD5 a4cc5605367161f74ce865c302aa7db8
BLAKE2b-256 837d119a879236b6b6dc9f043eabce379285b7a7c6f8f2bea97d4a0a23284f9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for composio_anthropic-0.18.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9ab95b2f95685f0eb4d6765dea002fa6c1d21d3f917a1e9fe5c792419e40b9e
MD5 05862481603431dfb7d8bba29f9d3127
BLAKE2b-256 7f55d0ace1b6987b2eb371d5a1222054aa5b831694498cc119eaef22991b9c49

See more details on using hashes here.

Supported by

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