Skip to main content

Anthropic (Claude) provider for Metorial

Project description

metorial-anthropic

Anthropic (Claude) provider integration for Metorial - enables using Metorial tools with Claude models through Anthropic's tool calling API.

Installation

pip install metorial-anthropic
# or
uv add metorial-anthropic
# or
poetry add metorial-anthropic

Features

  • 🤖 Claude Integration: Full support for Claude 3.5, Claude 3, and other Anthropic models
  • 🛠️ Tool Calling: Native Anthropic tool format support
  • 📡 Session Management: Automatic tool lifecycle handling
  • 🔄 Format Conversion: Converts Metorial tools to Anthropic tool format
  • Async Support: Full async/await support

Usage

Basic Usage

import asyncio
from anthropic import Anthropic
from metorial import Metorial
from metorial_anthropic import MetorialAnthropicSession

async def main():
    # Initialize clients
    metorial = Metorial(api_key="your-metorial-api-key")
    anthropic = Anthropic(api_key="your-anthropic-api-key")
    
    # Create session with your server deployments
    async with metorial.session(["your-server-deployment-id"]) as session:
        # Create Anthropic-specific wrapper
        anthropic_session = MetorialAnthropicSession(session.tool_manager)
        
        messages = [
            {"role": "user", "content": "What are the latest commits?"}
        ]
        
        # Remove duplicate tools by name (Anthropic requirement)
        unique_tools = list({t["name"]: t for t in anthropic_session.tools}.values())
        
        response = await anthropic.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=1024,
            messages=messages,
            tools=unique_tools
        )
        
        # Handle tool calls
        tool_calls = [c for c in response.content if c.type == "tool_use"]
        if tool_calls:
            tool_response = await anthropic_session.call_tools(tool_calls)
            messages.append({"role": "assistant", "content": response.content})
            messages.append(tool_response)
            
            # Continue conversation...

asyncio.run(main())

Using Convenience Functions

from metorial_anthropic import build_anthropic_tools, call_anthropic_tools

async def example_with_functions():
    # Get tools in Anthropic format
    tools = build_anthropic_tools(tool_manager)
    
    # Call tools from Anthropic response
    tool_response = await call_anthropic_tools(tool_manager, tool_calls)

API Reference

MetorialAnthropicSession

Main session class for Anthropic integration.

session = MetorialAnthropicSession(tool_manager)

Properties:

  • tools: List of tools in Anthropic format

Methods:

  • async call_tools(tool_calls): Execute tool calls and return user message

build_anthropic_tools(tool_mgr)

Build Anthropic-compatible tool definitions.

Returns: List of tool definitions in Anthropic format

call_anthropic_tools(tool_mgr, tool_calls)

Execute tool calls from Anthropic response.

Returns: User message with tool results

Tool Format

Tools are converted to Anthropic's format:

{
    "name": "tool_name",
    "description": "Tool description",
    "input_schema": {
        "type": "object",
        "properties": {...},
        "required": [...]
    }
}

Error Handling

try:
    tool_response = await anthropic_session.call_tools(tool_calls)
except Exception as e:
    print(f"Tool execution failed: {e}")

Tool errors are returned as error messages in the response format.

Dependencies

  • anthropic>=0.40.0
  • metorial-mcp-session>=1.0.0
  • typing-extensions>=4.0.0

License

MIT License - see LICENSE file for details.

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

metorial_anthropic-1.0.0rc1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

metorial_anthropic-1.0.0rc1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file metorial_anthropic-1.0.0rc1.tar.gz.

File metadata

  • Download URL: metorial_anthropic-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for metorial_anthropic-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 11801ea8e6324025875a4aa2debaea50cb2b0bf57ce5b19df0d784f390d2c5f7
MD5 cf7a616fec64d979435cd369aa0c2185
BLAKE2b-256 1e175da7812265fc0d4e42808eea1adc9a5f719bafe21992d4862fb418d367ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_anthropic-1.0.0rc1.tar.gz:

Publisher: release.yml on metorial/metorial-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metorial_anthropic-1.0.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for metorial_anthropic-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf81957cbb74c7815b58c03c3a3d2544c8c84531fb3d28560da2acce05f3fb6
MD5 44491c9556462284ffe538d02d331d53
BLAKE2b-256 1f3c4a0d144bfc6ed8333b6f22fec2c87f54eb2b0a900b8c2b805de9652be214

See more details on using hashes here.

Provenance

The following attestation bundles were made for metorial_anthropic-1.0.0rc1-py3-none-any.whl:

Publisher: release.yml on metorial/metorial-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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