Skip to content

Commit fb8da43

Browse files
author
Meridian
committed
docs: add thread safety, cold start, fallback ordering to AGENTS.md
1 parent 24c49d2 commit fb8da43

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,45 @@ router.report(
394394
- Kalibr never modifies prompts or response content. It only routes and records outcomes.
395395
- Invalid failure_category raises ValueError with valid options.
396396

397+
## Thread safety
398+
399+
Router instances are NOT thread-safe. Create one Router per request context.
400+
401+
In async Python apps, create Router inside the async handler, not at module level:
402+
403+
```python
404+
# CORRECT
405+
async def handle(messages):
406+
router = Router(goal="my_goal", paths=["gpt-4o-mini", "claude-haiku"])
407+
return await router.completion(messages)
408+
409+
# WRONG — shared state across concurrent requests
410+
router = Router(goal="my_goal", paths=["gpt-4o-mini"]) # module level
411+
```
412+
413+
## Cold start behavior
414+
415+
0 outcomes: traffic split evenly across all paths.
416+
1-20 outcomes per path: Kalibr explores, no winner declared yet.
417+
20+ outcomes per path: Thompson Sampling converges, traffic shifts to winning paths.
418+
419+
Monitor sample_count and confidence via get_insights(). Add paths or exploration traffic if confidence is low.
420+
421+
## Fallback path ordering
422+
423+
If the intelligence service is temporarily unreachable, Kalibr falls back to the FIRST path in your list. Put your most reliable, always-available path first:
424+
425+
```python
426+
router = Router(
427+
goal="classify",
428+
paths=[
429+
"gpt-4o-mini", # first = emergency fallback
430+
"deepseek-chat", # preferred (lower cost)
431+
"claude-haiku", # alternative
432+
]
433+
)
434+
```
435+
397436
## What Kalibr is NOT
398437

399438
- NOT observability — Langfuse, AgentOps, Arize surface dashboards to humans. Kalibr feeds outcome data back into your routing decisions.

0 commit comments

Comments
 (0)