[claude] Implement AdaptiveCalibrator for local cost estimation (#770) #809

Closed
claude wants to merge 1 commits from claude/issue-770 into main

1 Commits

Author SHA1 Message Date
Alexander Whitestone
5649aeb975 feat: Implement AdaptiveCalibrator for local cost estimation (Refs #770)
Some checks failed
CI / validate (pull_request) Has been cancelled
Add nexus/adaptive_calibrator.py with the AdaptiveCalibrator class that
provides online learning (EMA) for LLM inference cost prediction.

Key features:
- Per-model ModelCalibration state tracking ms/token and base overhead
- EMA updates from observed (prompt_tokens, completion_tokens, actual_ms)
- Confidence metric grows with sample count (1 - exp(-n/10))
- Seeded priors distinguish local Ollama models from Groq cloud models
- Atomic JSON persistence to ~/.nexus/calibrator_state.json
- reset() per-model or global; autosave on every record()
- 23 unit tests covering convergence, persistence, edge cases

Exported from nexus/__init__.py as AdaptiveCalibrator and CostPrediction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 21:39:28 -04:00