Skip to main content

High-performance Rust library for multi-provider LLM orchestration with native Python bindings

Project description

🐝 Colmena AI - Multi-Provider LLM Orchestration Library

A high-performance Rust library for AI agent orchestration with native Python bindings. Colmena provides a unified interface for multiple LLM providers with both synchronous and streaming support.

✨ Features

  • 🔌 Multi-Provider Support: Native support for OpenAI, Google Gemini, and Anthropic Claude
  • ⚡ Streaming Responses: Real-time text generation with chunk-by-chunk delivery
  • 🦀 Rust Performance: Native Rust implementation compiled with PyO3 (zero Python overhead)
  • 🏗️ Clean Architecture: Hexagonal architecture for maximum extensibility
  • 🔧 Flexible Configuration: API keys from environment variables or direct values
  • 🛡️ Robust Error Handling: Type-safe error management and recovery
  • 🔒 Type Safety: Compile-time guarantees from Rust's type system

🚀 Quick Start

Installation

pip install colmena-ai

Basic Usage

from colmena import ColmenaLlm

# Initialize the library
llm = ColmenaLlm()

# Simple synchronous call
response = llm.call(
    messages=[
        {"role": "user", "content": "What is the capital of France?"}
    ],
    provider="openai",
    model="gpt-4o",
    temperature=0.7
)

print(response)
# Output: "The capital of France is Paris."

Streaming Responses

from colmena import ColmenaLlm

llm = ColmenaLlm()

# Stream responses in real-time
for chunk in llm.stream(
    messages=["Tell me a story about AI"],
    provider="anthropic",
    model="claude-3-sonnet-20240229"
):
    print(chunk, end="", flush=True)

Multiple Providers

from colmena import ColmenaLlm

llm = ColmenaLlm()

# OpenAI
openai_response = llm.call(
    messages=[{"role": "user", "content": "Hello!"}],
    provider="openai",
    model="gpt-4o"
)

# Google Gemini
gemini_response = llm.call(
    messages=[{"role": "user", "content": "Hello!"}],
    provider="gemini",
    model="gemini-pro"
)

# Anthropic Claude
claude_response = llm.call(
    messages=[{"role": "user", "content": "Hello!"}],
    provider="anthropic",
    model="claude-3-sonnet-20240229"
)

🔑 Configuration

Environment Variables

Set API keys as environment variables:

export OPENAI_API_KEY="sk-..."
export GEMINI_API_KEY="AIza..."
export ANTHROPIC_API_KEY="sk-ant-..."

Direct API Keys

Or pass them directly:

llm.call(
    messages=[{"role": "user", "content": "Hello"}],
    provider="openai",
    api_key="sk-...",  # Direct API key
    model="gpt-4o"
)

📦 Supported Models

OpenAI

  • gpt-4o (default)
  • gpt-4-turbo
  • gpt-3.5-turbo

Google Gemini

  • gemini-pro (default)
  • gemini-2.0-flash-exp
  • gemini-1.5-pro

Anthropic Claude

  • claude-3-sonnet-20240229 (default)
  • claude-3-opus-20240229
  • claude-3-haiku-20240307

🎯 Advanced Configuration

from colmena import ColmenaLlm

llm = ColmenaLlm()

response = llm.call(
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum computing"}
    ],
    provider="openai",
    model="gpt-4o",
    temperature=0.7,        # Creativity (0.0 - 2.0)
    max_tokens=500,         # Maximum response length
    top_p=0.9,              # Nucleus sampling
    frequency_penalty=0.5,  # Reduce repetition
    presence_penalty=0.5    # Encourage new topics
)

🏗️ Architecture

Colmena is built using Hexagonal Architecture (Ports and Adapters):

  • Domain Layer: Pure business logic and interfaces
  • Application Layer: Use cases and orchestration
  • Infrastructure Layer: Provider adapters (OpenAI, Gemini, Anthropic)

This design ensures:

  • Easy to add new LLM providers
  • Testable and maintainable code
  • Clear separation of concerns

🔍 Error Handling

from colmena import ColmenaLlm

llm = ColmenaLlm()

try:
    response = llm.call(
        messages=[{"role": "user", "content": "Hello"}],
        provider="openai"
    )
except Exception as e:
    print(f"Error: {e}")
    # Handle error appropriately

🧪 Health Checks

from colmena import ColmenaLlm

llm = ColmenaLlm()

# Check if a provider is available
is_healthy = llm.health_check("openai")
print(f"OpenAI is {'available' if is_healthy else 'unavailable'}")

🌟 Why Colmena?

  1. Performance: Native Rust implementation, no Python overhead
  2. Unified API: One interface for all LLM providers
  3. Type Safety: Compile-time guarantees from Rust
  4. Extensible: Easy to add new providers following hexagonal architecture
  5. Production Ready: Robust error handling and testing

📚 Documentation

🤝 Contributing

Contributions are welcome! Please see our Contributing Guide.

📄 License

MIT License - see LICENSE for details.

🔗 Links


Built with ❤️ using Rust 🦀 and PyO3

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

colmena_ai-0.3.3.tar.gz (128.4 kB view details)

Uploaded Source

Built Distributions

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

colmena_ai-0.3.3-cp314-cp314-macosx_11_0_arm64.whl (5.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

colmena_ai-0.3.3-cp314-cp314-macosx_10_12_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

colmena_ai-0.3.3-cp312-cp312-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.12Windows x86-64

colmena_ai-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file colmena_ai-0.3.3.tar.gz.

File metadata

  • Download URL: colmena_ai-0.3.3.tar.gz
  • Upload date:
  • Size: 128.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for colmena_ai-0.3.3.tar.gz
Algorithm Hash digest
SHA256 1a1677c3fe2037b0dc7ea6c76cf26384718aba17addc03d0ac6357bf079af222
MD5 cce2a9e1cf450af5be1b84617efb449b
BLAKE2b-256 a488a84146598a545f8dbedd3b064841c32e2d60d621ae8cc34b48f509164dc5

See more details on using hashes here.

File details

Details for the file colmena_ai-0.3.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for colmena_ai-0.3.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5fa4a32ce7252a00436b92c9e13cf61de9d3c58a312147db18ae1b2cfb0e18e
MD5 a920e81e08dc01109e7628a0d7374405
BLAKE2b-256 23965e36406866fcfd9a3b6cc6cfbfa9953c49913ff1d4952406eefdbfa32bde

See more details on using hashes here.

File details

Details for the file colmena_ai-0.3.3-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for colmena_ai-0.3.3-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 31846a44b075c4ba056f7c75a66d43d28489c915a83273af53f0d90fd650d06d
MD5 a36bb09f54832583f012f17d5d272c69
BLAKE2b-256 96f5f874bec8a60f1c5ed4bfdb349d61b0f33fba5710cf8cb7b14e04144d5db0

See more details on using hashes here.

File details

Details for the file colmena_ai-0.3.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: colmena_ai-0.3.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for colmena_ai-0.3.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bd36615a0d397c68f11bb5ad02ca48bd96ed6462dada65e8e2087e70a8e2f962
MD5 5e9c028286fd28968d334802c339b5e3
BLAKE2b-256 883e0b6418e353a59f1c2805d2757e3a0f0d07e123f66a21d74b91e7e3e48c7c

See more details on using hashes here.

File details

Details for the file colmena_ai-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for colmena_ai-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2df426750a064cb25829bd504be968c8ff9d956b4482f9f983c1c5394c73fa6
MD5 034c0a64bee5f642e38e72c30a9d60de
BLAKE2b-256 05d940c224dfdf0d9154af1a9499a74e083f523afc91d910afa412a5f42c1725

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