Skip to main content

Provider-specific Swarmauri imports for Anthropic Claude Messages API chat, streaming, async, batch, and tool-use workflows.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_llm_anthropic Discord

Swarmauri Anthropic LLM

swarmauri_llm_anthropic provides provider-specific imports for Anthropic Claude models in Swarmauri. It re-exports AnthropicModel for standard Messages API chat workflows and AnthropicToolModel for tool-assisted conversations, both backed by the maintained implementations in swarmauri_standard.

Why Swarmauri Anthropic LLM?

Use this package when a Swarmauri application should depend explicitly on Anthropic Claude support while keeping the shared Swarmauri conversation and tool abstractions. The adapters send requests to Anthropic's /v1/messages endpoint, handle system-message extraction, support sync and async prediction, stream server-sent events, map token usage into Swarmauri UsageData, and connect Swarmauri toolkits to Anthropic tool schemas.

FAQ

Q: Which Anthropic API does this package use?

A: Both adapters use the Anthropic Messages API at https://api.anthropic.com/v1/messages with the anthropic-version header set to 2023-06-01.

Q: Which classes are exported?

A: The package exports AnthropicModel through the swarmauri.llms entry point and AnthropicToolModel through the swarmauri.tool_llms entry point.

Q: Which Claude model names are configured locally?

A: AnthropicModel and AnthropicToolModel include configured model IDs such as claude-opus-4-1, claude-opus-4-0, claude-sonnet-4-0, claude-3-7-sonnet-latest, and claude-3-5-haiku-latest. Set name explicitly in production.

Q: Does the tool model execute Swarmauri tools?

A: Yes. AnthropicToolModel converts Swarmauri toolkit tool schemas, sends them in the Anthropic tools payload, invokes matching Swarmauri tools when a tool_use block is returned, and adds the result to the conversation.

Features

  • Provider-specific imports for AnthropicModel and AnthropicToolModel.
  • Swarmauri Conversation, message, toolkit, and usage-data integration.
  • Sync predict() and async apredict() message generation.
  • Sync stream() and async astream() event streaming.
  • Sync batch() and async abatch() helpers for multiple conversations.
  • System-message extraction into Anthropic's top-level system field for AnthropicModel.
  • Toolkit schema conversion for AnthropicToolModel.
  • Retry handling for rate-limit and overloaded-provider status codes on the standard model.
  • Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.

Prerequisites

  • Anthropic API key from the Anthropic Console.
  • Network access to api.anthropic.com.
  • Swarmauri conversations and messages.
  • Swarmauri Toolkit objects when using AnthropicToolModel.

Installation

Install with uv:

uv add swarmauri_llm_anthropic

Install with pip:

pip install swarmauri_llm_anthropic

Usage

Run a standard Claude Messages API request:

import os

from swarmauri_llm_anthropic import AnthropicModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage
from swarmauri_standard.messages.SystemMessage import SystemMessage

conversation = Conversation()
conversation.add_message(SystemMessage(content="Answer in concise technical prose."))
conversation.add_message(HumanMessage(content="What is Swarmauri?"))

model = AnthropicModel(
    api_key=os.environ["ANTHROPIC_API_KEY"],
    name="claude-sonnet-4-0",
)
result = model.predict(conversation=conversation, max_tokens=256, temperature=0.2)

print(result.get_last().content)

Stream a Claude response:

import os

from swarmauri_llm_anthropic import AnthropicModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content="Draft a short API changelog entry."))

model = AnthropicModel(api_key=os.environ["ANTHROPIC_API_KEY"])

for token in model.stream(conversation=conversation, max_tokens=200):
    print(token, end="")

Use the tool model with a Swarmauri toolkit:

import os

from swarmauri_llm_anthropic import AnthropicToolModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage
from swarmauri_standard.toolkits.Toolkit import Toolkit

toolkit = Toolkit()
# toolkit.add_tool(...)

conversation = Conversation()
conversation.add_message(HumanMessage(content="Use an available tool if needed."))

model = AnthropicToolModel(api_key=os.environ["ANTHROPIC_API_KEY"])
result = model.predict(conversation=conversation, toolkit=toolkit)

print(result.get_last().content)

Related Packages

LLM provider packages:

Foundational packages:

Best Practices

  • Store ANTHROPIC_API_KEY in a secret manager or environment variable.
  • Set name explicitly for reproducible model behavior.
  • Use async methods for high-concurrency service workloads.
  • Keep system instructions in SystemMessage so the standard model can map them to Anthropic's system field.
  • Test tool schemas before production use so Anthropic tool calls map cleanly to Swarmauri toolkit functions.

License

Apache-2.0

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

swarmauri_llm_anthropic-0.11.0.dev1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

swarmauri_llm_anthropic-0.11.0.dev1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_llm_anthropic-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_llm_anthropic-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_llm_anthropic-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 31ece7b59c4faf99a36e273e6b0e1e4896a154700a82d8c331b40b32d02b6963
MD5 26eaac88446ebd4208166d40f2602b29
BLAKE2b-256 10203e6998c7eef6d417d7a035857ceebe6ec1765fa49968e38a7ad8970a7fc3

See more details on using hashes here.

File details

Details for the file swarmauri_llm_anthropic-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_llm_anthropic-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_llm_anthropic-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 89e12c0d4a88861d3078c2226d2ab8f340dd1ef9ec974e224f05041bf9291424
MD5 993cef304429bde961b6482b42c12b8d
BLAKE2b-256 90bef6556d4435eee5c7f1670a264f9a948566c2ef5db74cb9b7e60b952bcabf

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