kalibr 1.2.6__py3-none-any.whl → 1.2.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kalibr/__init__.py +2 -2
- kalibr/cli/capsule_cmd.py +3 -3
- kalibr/cli/run.py +2 -2
- kalibr/client.py +1 -1
- kalibr/collector.py +227 -48
- kalibr/cost_adapter.py +36 -104
- kalibr/instrumentation/anthropic_instr.py +34 -40
- kalibr/instrumentation/base.py +27 -9
- kalibr/instrumentation/google_instr.py +34 -39
- kalibr/instrumentation/openai_instr.py +34 -28
- kalibr/instrumentation/registry.py +38 -13
- kalibr/intelligence.py +28 -16
- kalibr/middleware/auto_tracer.py +1 -1
- kalibr/pricing.py +245 -0
- kalibr/router.py +139 -53
- kalibr/simple_tracer.py +16 -15
- kalibr/trace_capsule.py +19 -12
- kalibr/utils.py +2 -2
- {kalibr-1.2.6.dist-info → kalibr-1.2.8.dist-info}/METADATA +114 -14
- {kalibr-1.2.6.dist-info → kalibr-1.2.8.dist-info}/RECORD +24 -23
- {kalibr-1.2.6.dist-info → kalibr-1.2.8.dist-info}/LICENSE +0 -0
- {kalibr-1.2.6.dist-info → kalibr-1.2.8.dist-info}/WHEEL +0 -0
- {kalibr-1.2.6.dist-info → kalibr-1.2.8.dist-info}/entry_points.txt +0 -0
- {kalibr-1.2.6.dist-info → kalibr-1.2.8.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: kalibr
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.8
|
|
4
4
|
Summary: Adaptive routing for AI agents. Learns which models work best and routes automatically.
|
|
5
5
|
Author-email: Kalibr Team <support@kalibr.systems>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -67,7 +67,7 @@ Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
|
67
67
|
|
|
68
68
|
# Kalibr
|
|
69
69
|
|
|
70
|
-
Adaptive routing for AI agents. Kalibr learns which models
|
|
70
|
+
Adaptive routing for AI agents. Kalibr learns which models work best for your tasks and routes automatically.
|
|
71
71
|
|
|
72
72
|
[](https://pypi.org/project/kalibr/)
|
|
73
73
|
[](https://pypi.org/project/kalibr/)
|
|
@@ -83,24 +83,32 @@ pip install kalibr
|
|
|
83
83
|
from kalibr import Router
|
|
84
84
|
|
|
85
85
|
router = Router(
|
|
86
|
-
goal="
|
|
87
|
-
paths=["gpt-4o", "claude-sonnet-4-20250514"
|
|
88
|
-
success_when=lambda output: "confirmed" in output.lower()
|
|
86
|
+
goal="extract_company",
|
|
87
|
+
paths=["gpt-4o", "claude-sonnet-4-20250514"]
|
|
89
88
|
)
|
|
90
89
|
|
|
91
90
|
response = router.completion(
|
|
92
|
-
messages=[{"role": "user", "content": "
|
|
91
|
+
messages=[{"role": "user", "content": "Extract the company: Hi, I'm Sarah from Stripe."}]
|
|
93
92
|
)
|
|
93
|
+
|
|
94
|
+
router.report(success=True)
|
|
94
95
|
```
|
|
95
96
|
|
|
96
|
-
Kalibr picks the best model, makes the call,
|
|
97
|
+
Kalibr picks the best model, makes the call, and learns from the outcome.
|
|
98
|
+
|
|
99
|
+
## How It Works
|
|
100
|
+
|
|
101
|
+
1. **You define paths** - models (and optionally tools/params) that can handle your task
|
|
102
|
+
2. **Kalibr picks** - uses Thompson Sampling to balance exploration vs exploitation
|
|
103
|
+
3. **You report outcomes** - tell Kalibr if it worked
|
|
104
|
+
4. **Kalibr learns** - routes more traffic to what works
|
|
97
105
|
|
|
98
106
|
## Paths
|
|
99
107
|
|
|
100
108
|
A path is a model + optional tools + optional params:
|
|
101
109
|
```python
|
|
102
110
|
# Just models
|
|
103
|
-
paths = ["gpt-4o", "claude-sonnet-4-20250514"]
|
|
111
|
+
paths = ["gpt-4o", "claude-sonnet-4-20250514", "gpt-4o-mini"]
|
|
104
112
|
|
|
105
113
|
# With tools
|
|
106
114
|
paths = [
|
|
@@ -115,7 +123,78 @@ paths = [
|
|
|
115
123
|
]
|
|
116
124
|
```
|
|
117
125
|
|
|
118
|
-
##
|
|
126
|
+
## Advanced Path Configuration
|
|
127
|
+
|
|
128
|
+
### Routing Between Parameters
|
|
129
|
+
|
|
130
|
+
Kalibr can route between different parameter configurations of the same model:
|
|
131
|
+
```python
|
|
132
|
+
from kalibr import Router
|
|
133
|
+
|
|
134
|
+
router = Router(
|
|
135
|
+
goal="creative_writing",
|
|
136
|
+
paths=[
|
|
137
|
+
{"model": "gpt-4o", "params": {"temperature": 0.3}},
|
|
138
|
+
{"model": "gpt-4o", "params": {"temperature": 0.9}},
|
|
139
|
+
{"model": "claude-sonnet-4-20250514", "params": {"temperature": 0.7}}
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
response = router.completion(messages=[...])
|
|
144
|
+
router.report(success=True)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Each unique `(model, params)` combination is tracked separately. Kalibr learns which configuration works best for your specific goal.
|
|
148
|
+
|
|
149
|
+
### Routing Between Tools
|
|
150
|
+
```python
|
|
151
|
+
router = Router(
|
|
152
|
+
goal="research_task",
|
|
153
|
+
paths=[
|
|
154
|
+
{"model": "gpt-4o", "tools": ["web_search"]},
|
|
155
|
+
{"model": "gpt-4o", "tools": ["code_interpreter"]},
|
|
156
|
+
{"model": "claude-sonnet-4-20250514"}
|
|
157
|
+
]
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### When to Use get_policy() Instead of Router
|
|
162
|
+
|
|
163
|
+
For most use cases, use `Router`. It handles provider dispatching and response conversion automatically.
|
|
164
|
+
|
|
165
|
+
Use `get_policy()` for advanced scenarios:
|
|
166
|
+
- Integrating with frameworks like LangChain that wrap LLM calls
|
|
167
|
+
- Custom retry logic or provider-specific features
|
|
168
|
+
- Building tools that need fine-grained control
|
|
169
|
+
```python
|
|
170
|
+
from kalibr import get_policy, report_outcome
|
|
171
|
+
|
|
172
|
+
policy = get_policy(goal="summarize")
|
|
173
|
+
model = policy["recommended_model"]
|
|
174
|
+
|
|
175
|
+
# You call the provider yourself
|
|
176
|
+
if model.startswith("gpt"):
|
|
177
|
+
client = OpenAI()
|
|
178
|
+
response = client.chat.completions.create(model=model, messages=[...])
|
|
179
|
+
|
|
180
|
+
report_outcome(trace_id=trace_id, goal="summarize", success=True)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Outcome Reporting
|
|
184
|
+
|
|
185
|
+
### Automatic (with success_when)
|
|
186
|
+
```python
|
|
187
|
+
router = Router(
|
|
188
|
+
goal="summarize",
|
|
189
|
+
paths=["gpt-4o", "claude-sonnet-4-20250514"],
|
|
190
|
+
success_when=lambda output: len(output) > 100
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
response = router.completion(messages=[...])
|
|
194
|
+
# Outcome reported automatically based on success_when
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Manual
|
|
119
198
|
```python
|
|
120
199
|
router = Router(goal="book_meeting", paths=["gpt-4o", "claude-sonnet-4-20250514"])
|
|
121
200
|
response = router.completion(messages=[...])
|
|
@@ -139,7 +218,7 @@ chain = prompt | llm | parser
|
|
|
139
218
|
|
|
140
219
|
## Auto-Instrumentation
|
|
141
220
|
|
|
142
|
-
Kalibr auto-instruments OpenAI, Anthropic, and Google SDKs
|
|
221
|
+
Kalibr auto-instruments OpenAI, Anthropic, and Google SDKs on import:
|
|
143
222
|
```python
|
|
144
223
|
import kalibr # Must be first import
|
|
145
224
|
from openai import OpenAI
|
|
@@ -151,19 +230,39 @@ response = client.chat.completions.create(model="gpt-4o", messages=[...])
|
|
|
151
230
|
|
|
152
231
|
Disable with `KALIBR_AUTO_INSTRUMENT=false`.
|
|
153
232
|
|
|
233
|
+
## Low-Level API
|
|
234
|
+
|
|
235
|
+
For advanced use cases, you can use the intelligence API directly:
|
|
236
|
+
```python
|
|
237
|
+
from kalibr import register_path, decide, report_outcome
|
|
238
|
+
|
|
239
|
+
# Register paths
|
|
240
|
+
register_path(goal="book_meeting", model_id="gpt-4o")
|
|
241
|
+
register_path(goal="book_meeting", model_id="claude-sonnet-4-20250514")
|
|
242
|
+
|
|
243
|
+
# Get routing decision
|
|
244
|
+
decision = decide(goal="book_meeting")
|
|
245
|
+
model = decision["model_id"]
|
|
246
|
+
|
|
247
|
+
# Make your own LLM call, then report
|
|
248
|
+
report_outcome(trace_id="...", goal="book_meeting", success=True)
|
|
249
|
+
```
|
|
250
|
+
|
|
154
251
|
## Other Integrations
|
|
155
252
|
```bash
|
|
156
253
|
pip install kalibr[crewai] # CrewAI
|
|
157
254
|
pip install kalibr[openai-agents] # OpenAI Agents SDK
|
|
255
|
+
pip install kalibr[langchain-all] # LangChain with all providers
|
|
158
256
|
```
|
|
159
257
|
|
|
160
258
|
## Configuration
|
|
161
259
|
|
|
162
260
|
| Variable | Description | Default |
|
|
163
261
|
|----------|-------------|---------|
|
|
164
|
-
| `KALIBR_API_KEY` | API key | Required |
|
|
165
|
-
| `KALIBR_TENANT_ID` | Tenant ID |
|
|
166
|
-
| `KALIBR_AUTO_INSTRUMENT` | Auto-instrument SDKs | `true` |
|
|
262
|
+
| `KALIBR_API_KEY` | API key from dashboard | Required |
|
|
263
|
+
| `KALIBR_TENANT_ID` | Tenant ID from dashboard | Required |
|
|
264
|
+
| `KALIBR_AUTO_INSTRUMENT` | Auto-instrument LLM SDKs | `true` |
|
|
265
|
+
| `KALIBR_INTELLIGENCE_URL` | Intelligence service URL | `https://kalibr-intelligence.fly.dev` |
|
|
167
266
|
|
|
168
267
|
## Development
|
|
169
268
|
```bash
|
|
@@ -183,5 +282,6 @@ Apache-2.0
|
|
|
183
282
|
|
|
184
283
|
## Links
|
|
185
284
|
|
|
186
|
-
- [Docs](https://kalibr.
|
|
285
|
+
- [Docs](https://kalibr.dev/docs)
|
|
187
286
|
- [Dashboard](https://dashboard.kalibr.systems)
|
|
287
|
+
- [GitHub](https://github.com/kalibr-ai/kalibr-sdk-python)
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
kalibr/__init__.py,sha256=
|
|
1
|
+
kalibr/__init__.py,sha256=XyXmJHqHs3-bW8pbAMlJDrVjOD0X6-KvqcoI7YmGtPA,5189
|
|
2
2
|
kalibr/__main__.py,sha256=jO96I4pqinwHg7ONRvNVKbySBh5pSIhOAiNrgSQrNlY,110
|
|
3
3
|
kalibr/capsule_middleware.py,sha256=pXG_wORgCqo3wHjtkn_zY4doLyiDmTwJtB7XiZNnbPk,3163
|
|
4
|
-
kalibr/client.py,sha256=
|
|
5
|
-
kalibr/collector.py,sha256=
|
|
4
|
+
kalibr/client.py,sha256=oiGN4DrdLuNVLFC_KEUjEYACcLAlcErAcB9dSyx2wYA,9736
|
|
5
|
+
kalibr/collector.py,sha256=2iQ_NQgO-rZHirwlWbfDWf_4koGSRoa_56ngattWvaU,12817
|
|
6
6
|
kalibr/context.py,sha256=FgN9-WyMQMDgg2Vqwje4r2_jKRvnMeI8t4fIE1VRn_8,4777
|
|
7
|
-
kalibr/cost_adapter.py,sha256=
|
|
7
|
+
kalibr/cost_adapter.py,sha256=uHcJpndNx895EcY68YFSZisRnO8j4i13L3iskg4bIco,4484
|
|
8
8
|
kalibr/decorators.py,sha256=m-XBXxWMDVrzaNsljACiGmeGhgiHj_MqSfj6OGK3L5I,4380
|
|
9
|
-
kalibr/intelligence.py,sha256=
|
|
9
|
+
kalibr/intelligence.py,sha256=Pky43AMB2VW4FogRvTtc2JXjvD2Ov9_TazHHb2byVXE,22865
|
|
10
10
|
kalibr/kalibr.py,sha256=cNXC3W_TX5SvGsy1lRopkwFqsHOpyd1kkVjEMOz1Yr4,6084
|
|
11
11
|
kalibr/kalibr_app.py,sha256=ItZwEh0FZPx9_BE-zPQajC2yxI2y9IHYwJD0k9tbHvY,2773
|
|
12
12
|
kalibr/models.py,sha256=HwD_-iysZMSnCzMQYO1Qcf0aeXySupY7yJeBwl_dLS0,1024
|
|
13
|
+
kalibr/pricing.py,sha256=wY0GzcrZdXuHlZoq2e74RkX0scd6somk_KYbr-RSHdE,8844
|
|
13
14
|
kalibr/redaction.py,sha256=XibxX4Lv1Ci0opE6Tb5ZI2GLbO0a8E9U66MAg60llnc,1139
|
|
14
|
-
kalibr/router.py,sha256=
|
|
15
|
+
kalibr/router.py,sha256=ari4XOogl3tzvcVlGc1Qg3hOnYI2hGaCweLXx07f_fU,17820
|
|
15
16
|
kalibr/schemas.py,sha256=XLZNLkXca6jbj9AF6gDIyGVnIcr1SVOsNYaKvW-wbgE,3669
|
|
16
|
-
kalibr/simple_tracer.py,sha256=
|
|
17
|
+
kalibr/simple_tracer.py,sha256=oiwXtiYaIqZxqCNV-b79_dsiJT0D3XvKhNT_LF6bRD4,9736
|
|
17
18
|
kalibr/tokens.py,sha256=istjgaxi9S4dMddjuGtoQaTnZYcWLCqdnxRjV86yNXA,1297
|
|
18
|
-
kalibr/trace_capsule.py,sha256=
|
|
19
|
+
kalibr/trace_capsule.py,sha256=SEfTE-GXvM9kcGCOZ5uEQSD8AnbmRRA0UUu0X8c8isw,10492
|
|
19
20
|
kalibr/trace_models.py,sha256=9o7VJQk3gCrvdfXPrNh3Ptkq5sRgA9_qrLLE3jNkSBg,7304
|
|
20
21
|
kalibr/tracer.py,sha256=jwWBpZbGXn6fEv4pw25BLFCH-22QUbyzofPWp1Iwdkk,11911
|
|
21
22
|
kalibr/types.py,sha256=cna4-akpdwfHXfOJCtVIq5lO_jaoG2Am3BRrXi0Vo34,895
|
|
22
|
-
kalibr/utils.py,sha256=
|
|
23
|
+
kalibr/utils.py,sha256=NQbC9ygJJWZUNfkUW7FheftraBs8QT6sDzwuNeQklxM,5060
|
|
23
24
|
kalibr/cli/__init__.py,sha256=FmRGaDMhM9DhrKg1ONkF0emIrJcjFWjlFBl_oenvpsk,77
|
|
24
|
-
kalibr/cli/capsule_cmd.py,sha256=
|
|
25
|
+
kalibr/cli/capsule_cmd.py,sha256=I3vm5-V0T36ykiKunIxhbCdmxG4xMwFrFFC2pBfKD_0,6109
|
|
25
26
|
kalibr/cli/deploy_cmd.py,sha256=kV4uqCN2IdQev1vPBY5qqIHsEhjGBZ7y_rLx8RGAL_4,5178
|
|
26
27
|
kalibr/cli/main.py,sha256=FrOSIACNARkrvq-J2SZhyPNWNCdNEMZlD69PEV3uCMA,1924
|
|
27
|
-
kalibr/cli/run.py,sha256=
|
|
28
|
+
kalibr/cli/run.py,sha256=ZbfJB2TtsLi-T2noKkAaRJMm6xfO6ytwTGAWEolqKE8,6441
|
|
28
29
|
kalibr/cli/serve.py,sha256=71Xha35qrBNkcQxuUkwC-ixbOriHGUIEgxl7C_qERQo,2085
|
|
29
30
|
kalibr/instrumentation/__init__.py,sha256=YnUJ4gUH8WNxdVv5t1amn0l2WUULJG2MuQIL2ZZhn04,354
|
|
30
|
-
kalibr/instrumentation/anthropic_instr.py,sha256=
|
|
31
|
-
kalibr/instrumentation/base.py,sha256=
|
|
32
|
-
kalibr/instrumentation/google_instr.py,sha256=
|
|
33
|
-
kalibr/instrumentation/openai_instr.py,sha256=
|
|
34
|
-
kalibr/instrumentation/registry.py,sha256=
|
|
31
|
+
kalibr/instrumentation/anthropic_instr.py,sha256=ChH4-0PSALwXl_UJnXzf1KsuyjpKjmxDepmP60AfAVs,9601
|
|
32
|
+
kalibr/instrumentation/base.py,sha256=EW3kRJo11HzuiOwgvJESSzk_Roo1r2oKz51c-PZH3KM,3666
|
|
33
|
+
kalibr/instrumentation/google_instr.py,sha256=hfczy4ofNtdqPujD7yUCWf-T3TztaNnK-vUajIVBxZo,10073
|
|
34
|
+
kalibr/instrumentation/openai_instr.py,sha256=qIXNzCZtco7kfWTL1u6fMojtLerZ0K_ilr8noj-wDkQ,9287
|
|
35
|
+
kalibr/instrumentation/registry.py,sha256=uOlbEDHmrlItFYV69ANSRzD_722Ym5cZ57dyejuDY1E,5645
|
|
35
36
|
kalibr/middleware/__init__.py,sha256=qyDUn_irAX67MS-IkuDVxg4RmFnJHDf_BfIT3qfGoBI,115
|
|
36
|
-
kalibr/middleware/auto_tracer.py,sha256=
|
|
37
|
+
kalibr/middleware/auto_tracer.py,sha256=pFwGiwDhaEQ6x35TpMX8Y0DD2tjajO2JZADvkzlMVR0,13041
|
|
37
38
|
kalibr_crewai/__init__.py,sha256=b0HFTiE80eArtSMBOIEKu1JM6KU0tCjEylKCVVVF29Q,1796
|
|
38
39
|
kalibr_crewai/callbacks.py,sha256=_d1M4J-6XfKqrVIxnOgOQu57jpFKVv-VIsmPV0HNgZ4,20419
|
|
39
40
|
kalibr_crewai/instrumentor.py,sha256=-G_-xaqE3Op70MSEIaZjPYioGDxKRagwLbZmcmmvzFg,26793
|
|
@@ -43,9 +44,9 @@ kalibr_langchain/callback.py,sha256=SNM1aHOXdG55grHmGyTwbXOeM6hjZTub2REiZD2H-d8,
|
|
|
43
44
|
kalibr_langchain/chat_model.py,sha256=Y4xsZGx9gZpDUF8NP-edJuYam4k0NBySdA6B5484MKk,3190
|
|
44
45
|
kalibr_openai_agents/__init__.py,sha256=wL59LzGstptKigfQDrKKt_7hcMO1JGVQtVAsE0lz-Zw,1367
|
|
45
46
|
kalibr_openai_agents/processor.py,sha256=F550sdRf3rpguP1yOlgAUQWDLPBy4hSACV3-zOyCpOU,18257
|
|
46
|
-
kalibr-1.2.
|
|
47
|
-
kalibr-1.2.
|
|
48
|
-
kalibr-1.2.
|
|
49
|
-
kalibr-1.2.
|
|
50
|
-
kalibr-1.2.
|
|
51
|
-
kalibr-1.2.
|
|
47
|
+
kalibr-1.2.8.dist-info/LICENSE,sha256=5mwAnB38l3_PjmOQn6_L6cZnJvus143DUjMBPIH1yso,10768
|
|
48
|
+
kalibr-1.2.8.dist-info/METADATA,sha256=DR_yUR8AmRmGL3Wgp9EhMaIkGIvzh9es5S_1v7b8vEM,9014
|
|
49
|
+
kalibr-1.2.8.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
50
|
+
kalibr-1.2.8.dist-info/entry_points.txt,sha256=Kojlc6WRX8V1qS9lOMdDPZpTUVHCtzGtHqXusErgmLY,47
|
|
51
|
+
kalibr-1.2.8.dist-info/top_level.txt,sha256=dIfBOWUnnHGFDwgz5zfIx5_0bU3wOUgAbYr4JcFHZmo,59
|
|
52
|
+
kalibr-1.2.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|