Skip to content

feat(cost): add CPS metric to CostTracker#3322

Merged
bug-ops merged 1 commit intomainfrom
slm-cost-metrics
Apr 24, 2026
Merged

feat(cost): add CPS metric to CostTracker#3322
bug-ops merged 1 commit intomainfrom
slm-cost-metrics

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 24, 2026

Summary

  • Adds record_successful_task(), cps() -> Option<f64>, and successful_tasks() -> u64 to CostTracker in zeph-core — tracks Cost Per Successful Task (CPS) per day, resets at UTC midnight alongside existing cost counters.
  • Wires record_successful_task() after every record_cost_and_cache() call site in native.rs and plan.rs.
  • Adds cost_cps_cents: Option<f64> and cost_successful_tasks: u64 to AgentMetrics.
  • Adds commented-out slm-medium Qwen-2.5-7B Ollama provider entry to .local/config/testing.toml.
  • Adds spec 048-slm-cost-metrics documenting SLM survey findings (arXiv:2510.03847) and CPS metric contract.

Based on SLM survey findings: SLMs (1–12B params) are sufficient for tool calling/RAG at 10x–100x lower cost; CPS is the production metric that makes this cost reduction measurable per turn.

Test plan

  • cargo nextest run -p zeph-core -E 'test(cps)' — 3 new CPS tests pass
  • cargo nextest run -p zeph-core --lib — all 23 cost tests pass
  • Live session: send 3 turns, verify cost_successful_tasks = 3 and cost_cps_cents is non-None
  • Disabled tracker: verify cps() returns None and counter stays 0

Closes #2194

Implement Cost Per Successful Task (CPS) tracking based on SLM survey
findings from arXiv:2510.03847. CPS = total_spent_cents / successful_tasks
and resets daily alongside existing cost counters.

- Add `successful_tasks: u64` to `CostState`; reset in `reset_if_new_day`
- Add `record_successful_task()`, `cps() -> Option<f64>`, `successful_tasks()`
  to `CostTracker`
- Wire `record_successful_task()` in `utils.rs` after `record_cost_and_cache`;
  called from `native.rs` (lines 379, 1033) and `plan.rs` (lines 491, 728)
- Add `cost_cps_cents: Option<f64>` and `cost_successful_tasks: u64` to
  `AgentMetrics`
- Add spec `048-slm-cost-metrics` documenting SLM applicability and CPS contract

Closes #2194
@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate enhancement New feature or request size/M Medium PR (51-200 lines) labels Apr 24, 2026
@bug-ops bug-ops enabled auto-merge (squash) April 24, 2026 01:53
@bug-ops bug-ops merged commit c05a7df into main Apr 24, 2026
32 checks passed
@bug-ops bug-ops deleted the slm-cost-metrics branch April 24, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

research(cost): SLM survey — SLMs sufficient for tool calling/RAG at 10x-100x lower cost (arXiv:2510.03847)

1 participant