AI Agent Orchestration Library - LLM abstraction layer with multi-provider support
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-turbogpt-3.5-turbo
Google Gemini
gemini-pro(default)gemini-2.0-flash-expgemini-1.5-pro
Anthropic Claude
claude-3-sonnet-20240229(default)claude-3-opus-20240229claude-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?
- Performance: Native Rust implementation, no Python overhead
- Unified API: One interface for all LLM providers
- Type Safety: Compile-time guarantees from Rust
- Extensible: Easy to add new providers following hexagonal architecture
- 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
- Repository: https://github.com/Startti/colmena
- Issues: https://github.com/Startti/colmena/issues
- PyPI: https://pypi.org/project/colmena-ai/
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colmena_ai-0.2.0.tar.gz.
File metadata
- Download URL: colmena_ai-0.2.0.tar.gz
- Upload date:
- Size: 229.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68c5304f4bfc4371487e7b62dc3a4ce3ba64db66bab3009e87380cd5d989ff03
|
|
| MD5 |
9836fe917cea770175c57600f6e523d2
|
|
| BLAKE2b-256 |
b34ae571ce249a1855dbcbd0abc23a681e4c8652c368f6ba834379acdce8f00d
|
File details
Details for the file colmena_ai-0.2.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: colmena_ai-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0085870f1401edff75252c3700c46ce59a602b5bf6862d5ece893f9d0ca7541
|
|
| MD5 |
9452dab59bd4d0d54156a32e48ad6bd6
|
|
| BLAKE2b-256 |
415a96a926f5165727375fe81003548b64053b11468e24980c8fa602b1721858
|
File details
Details for the file colmena_ai-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl.
File metadata
- Download URL: colmena_ai-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl
- Upload date:
- Size: 5.7 MB
- Tags: CPython 3.14, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52ef5fedc1c9f14cdc62c0f400e1e8c42f863c4b23ac5e4290c9fc50b76225eb
|
|
| MD5 |
01038947889dbe4bd693474c13898a60
|
|
| BLAKE2b-256 |
335f74094ef4873de8f25ee63b5fe5c984c84aec46a7ce6bee27ddf4e34459c5
|
File details
Details for the file colmena_ai-0.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: colmena_ai-0.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 5.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bf86bc54ddb703c49d57bbb7ec066352eaed10c83ed22d365f127601f9be938
|
|
| MD5 |
fa3e45f0c7ac9792d1719d230c70768b
|
|
| BLAKE2b-256 |
9c012dca2374e204ae38d77242b3b35a8ea34c4a7853befe10b6cc6db7a5cf92
|
File details
Details for the file colmena_ai-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: colmena_ai-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1da5cb474c1682fa8f7dc9397f68b7ed1c19db89bda6a4b2af832350e85e20b5
|
|
| MD5 |
d557556517e82581fb6bc0a9ae00b241
|
|
| BLAKE2b-256 |
f14a1884cb47ea28caa02d525c38681117463012ee39a1ac994f681e597d8e17
|