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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for composio_anthropic-0.18.0.tar.gz
Algorithm Hash digest
SHA256 18df7b5bd162841e6738fc87a9b38b67e99ae932dd1242f1d8f36b8154fff6ab
MD5 4960bea25ea769733aff198f5eff85fb
BLAKE2b-256 e84b1c7a2a4853ee699db0aaccaaf80370772380f8687470c35b271f51d30d3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for composio_anthropic-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ed4f29b37749476e75ce558ba2761c63cc22b897829289633ff86e39b2030fc
MD5 6809ba1b61bbc2f09285a5ba606560f6
BLAKE2b-256 1171bbc8ba1ff7eb0e1c42bfc29e45fb723e32c0a028d515e25c78b73826b5dc

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