Adaptive routing for AI agents. Learns which models work best and routes automatically.
Project description
Kalibr
Adaptive routing for AI agents. Kalibr learns which models work best for your tasks and routes automatically.
Installation
pip install kalibr
Quick Start
from kalibr import Router
router = Router(
goal="extract_company",
paths=["gpt-4o", "claude-sonnet-4-20250514"]
)
response = router.completion(
messages=[{"role": "user", "content": "Extract the company: Hi, I'm Sarah from Stripe."}]
)
router.report(success=True)
Kalibr picks the best model, makes the call, and learns from the outcome.
How It Works
- You define paths - models (and optionally tools/params) that can handle your task
- Kalibr picks - uses Thompson Sampling to balance exploration vs exploitation
- You report outcomes - tell Kalibr if it worked
- Kalibr learns - routes more traffic to what works
Paths
A path is a model + optional tools + optional params:
# Just models
paths = ["gpt-4o", "claude-sonnet-4-20250514", "gpt-4o-mini"]
# With tools
paths = [
{"model": "gpt-4o", "tools": ["web_search"]},
{"model": "claude-sonnet-4-20250514", "tools": ["web_search", "browser"]},
]
# With params
paths = [
{"model": "gpt-4o", "params": {"temperature": 0.7}},
{"model": "gpt-4o", "params": {"temperature": 0.2}},
]
Outcome Reporting
Automatic (with success_when)
router = Router(
goal="summarize",
paths=["gpt-4o", "claude-sonnet-4-20250514"],
success_when=lambda output: len(output) > 100
)
response = router.completion(messages=[...])
# Outcome reported automatically based on success_when
Manual
router = Router(goal="book_meeting", paths=["gpt-4o", "claude-sonnet-4-20250514"])
response = router.completion(messages=[...])
meeting_created = check_calendar_api()
router.report(success=meeting_created)
LangChain Integration
pip install kalibr[langchain]
from kalibr import Router
router = Router(goal="summarize", paths=["gpt-4o", "claude-sonnet-4-20250514"])
llm = router.as_langchain()
chain = prompt | llm | parser
Auto-Instrumentation
Kalibr auto-instruments OpenAI, Anthropic, and Google SDKs on import:
import kalibr # Must be first import
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(model="gpt-4o", messages=[...])
# Traced automatically
Disable with KALIBR_AUTO_INSTRUMENT=false.
Low-Level API
For advanced use cases, you can use the intelligence API directly:
from kalibr import register_path, decide, report_outcome
# Register paths
register_path(goal="book_meeting", model_id="gpt-4o")
register_path(goal="book_meeting", model_id="claude-sonnet-4-20250514")
# Get routing decision
decision = decide(goal="book_meeting")
model = decision["model_id"]
# Make your own LLM call, then report
report_outcome(trace_id="...", goal="book_meeting", success=True)
Other Integrations
pip install kalibr[crewai] # CrewAI
pip install kalibr[openai-agents] # OpenAI Agents SDK
pip install kalibr[langchain-all] # LangChain with all providers
Configuration
| Variable | Description | Default |
|---|---|---|
KALIBR_API_KEY |
API key from dashboard | Required |
KALIBR_TENANT_ID |
Tenant ID from dashboard | Required |
KALIBR_AUTO_INSTRUMENT |
Auto-instrument LLM SDKs | true |
KALIBR_INTELLIGENCE_URL |
Intelligence service URL | https://kalibr-intelligence.fly.dev |
Development
git clone https://github.com/kalibr-ai/kalibr-sdk-python.git
cd kalibr-sdk-python
pip install -e ".[dev]"
pytest
Contributing
See CONTRIBUTING.md.
License
Apache-2.0
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 kalibr-1.2.7.tar.gz.
File metadata
- Download URL: kalibr-1.2.7.tar.gz
- Upload date:
- Size: 89.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc84147039a3fee89af21ef4a1146b52079cd38eb504384126a7143ae98a0da9
|
|
| MD5 |
9e36225adcc9b30526594de4c665ed81
|
|
| BLAKE2b-256 |
db2badf1c3ae380a9efc8c10deb3a75efe679117b9e8e7dfd785c8561a3ecdf9
|
File details
Details for the file kalibr-1.2.7-py3-none-any.whl.
File metadata
- Download URL: kalibr-1.2.7-py3-none-any.whl
- Upload date:
- Size: 102.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d70f6494341dcf890e5d032830716719a3eeda1b393dfee184cb1e1bb8c29c1
|
|
| MD5 |
3a0d2e476559a9f94452244f6a452be8
|
|
| BLAKE2b-256 |
d718eaac6f2c22a7cd37fe3b1d7c228a067133b84053343b6c2ec0561831dd28
|