Skip to main content

Provider-specific Swarmauri imports for Cohere Command chat, streaming, async, batch, preamble, and tool-use workflows.

Project description

Swarmauri Logo

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

Swarmauri Cohere LLM

swarmauri_llm_cohere provides provider-specific imports for Cohere Command models in Swarmauri. It re-exports CohereModel for standard chat workflows and CohereToolModel for tool-assisted conversations, both backed by the maintained implementations in swarmauri_standard.

Why Swarmauri Cohere LLM?

Use this package when a Swarmauri application should depend explicitly on Cohere chat support while preserving Swarmauri conversations, messages, toolkits, usage records, streaming, and batch workflows. The adapters call Cohere API v1 /chat, map Swarmauri system messages to Cohere preamble, pass prior messages as chat_history, and support Command model families used for enterprise chat, RAG, multilingual, and tool-use workloads.

FAQ

Q: Which Cohere API does this package use?

A: The current adapters call Cohere API v1 at https://api.cohere.ai/v1/chat. They do not yet target the newer /v2/chat endpoint.

Q: Which classes are exported?

A: The package exports CohereModel through the swarmauri.llms entry point and CohereToolModel through the swarmauri.tool_llms entry point.

Q: Which model names are configured locally?

A: The configured list includes command-a-03-2025, command-r7b-12-2024, command-a-translate-08-2025, command-a-reasoning-08-2025, command-a-vision-07-2025, command-r-plus, command-r, command, and related dated aliases. The default is command-a-03-2025.

Q: How does tool use work?

A: CohereToolModel converts Swarmauri toolkit tools into Cohere-compatible tool schemas, sends an initial /chat request with tools, executes returned tool calls with the Swarmauri toolkit, then sends a second /chat request with tool_results.

Features

  • Provider-specific imports for CohereModel and CohereToolModel.
  • Swarmauri Conversation, message, toolkit, and usage-data integration.
  • Sync predict() and async apredict() chat calls.
  • Sync stream() and async astream() response streaming.
  • Sync batch() and async abatch() helpers.
  • Cohere v1 preamble support from Swarmauri system messages.
  • Cohere v1 chat_history construction from previous Swarmauri messages.
  • Cohere tool schema conversion and tool result submission in CohereToolModel.
  • Retry handling for rate-limit and overloaded-provider status codes.
  • Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.

Prerequisites

  • Cohere API key from the Cohere dashboard.
  • Network access to api.cohere.ai.
  • Swarmauri conversations built from Swarmauri message classes.
  • Swarmauri Toolkit objects when using CohereToolModel.

Installation

Install with uv:

uv add swarmauri_llm_cohere

Install with pip:

pip install swarmauri_llm_cohere

Usage

Run a standard Cohere chat request:

import os

from swarmauri_llm_cohere import CohereModel
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 with concise technical prose."))
conversation.add_message(HumanMessage(content="What is Cohere Command A?"))

model = CohereModel(
    api_key=os.environ["COHERE_API_KEY"],
    name="command-a-03-2025",
)
result = model.predict(conversation=conversation, max_tokens=256, temperature=0.2)

print(result.get_last().content)

Stream a response:

import os

from swarmauri_llm_cohere import CohereModel
from swarmauri_standard.conversations.Conversation import Conversation
from swarmauri_standard.messages.HumanMessage import HumanMessage

conversation = Conversation()
conversation.add_message(HumanMessage(content="Draft a short support response."))

model = CohereModel(api_key=os.environ["COHERE_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_cohere import CohereToolModel
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 = CohereToolModel(api_key=os.environ["COHERE_API_KEY"])
result = model.predict(conversation=conversation, toolkit=toolkit)

print(result.get_last().content)

Related Packages

LLM provider packages:

Foundational packages:

Best Practices

  • Store COHERE_API_KEY in a secret manager or environment variable.
  • Set name explicitly for reproducible model behavior.
  • Use CohereToolModel only with tool schemas that have been tested against Cohere's v1 tool format.
  • Use async methods for high-concurrency service workloads.
  • Capture Swarmauri UsageData for cost and latency monitoring when Cohere returns usage fields.

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_cohere-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_cohere-0.11.0.dev1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: swarmauri_llm_cohere-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_cohere-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 cbb95da154994dd3098273bfbd5bf227d2c3431cce4a5d6336be735425ffcfbe
MD5 c89b5d706f29fca60659b2af9dab9516
BLAKE2b-256 553fa87dc3bc784f2975ebb4403b9d44e6b18bad4859d36b8f192ee12e44157f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_llm_cohere-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 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_cohere-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0458d05c27cc8dc7df384bffaf891d765cb99371bbf5d10766713cd3257535d
MD5 8865a608f65363949cbe860e4cc32c0a
BLAKE2b-256 5eae0d82be031911c49e1eca9532d4c93bc7a34fc0671384d48b7e99e17dc714

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