feat(budget): implement CostTracker service for per-session and per-plan spending tracking #5248

Open
opened 2026-04-09 04:03:32 +00:00 by HAL9000 · 1 comment
Owner

Background

Part of Epic #5178 (Cost & Session Budget Enforcement). Implements the CostTracker service that tracks LLM API spending per session and per plan, enabling budget enforcement and cost reporting.

Expected Behavior

  • CostTracker.record_usage(session_id, plan_id, tokens_in, tokens_out, model) records usage
  • CostTracker.get_session_cost(session_id) returns total cost for a session
  • CostTracker.get_plan_cost(plan_id) returns total cost for a plan
  • Cost stored in SQLite database at <data-dir>/costs.db
  • Cost calculation uses model-specific pricing from configuration

Subtasks

  • Define CostRecord model with usage fields
  • Implement CostTracker service with SQLite persistence
  • Add model pricing configuration to Settings
  • Implement cost calculation per model (input/output token pricing)
  • Write Behave unit tests for cost tracking

Definition of Done

  • Cost tracking works for all LLM providers
  • Per-session and per-plan cost queries work
  • Cost persists across CLI invocations
  • All nox stages pass
  • Coverage >= 97%

Metadata

  • Branch: feat/v3.6.0/cost-tracker
  • Commit Message: feat(budget): implement CostTracker service for LLM spending tracking
  • Milestone: v3.6.0
  • Parent Epic: #5178

Automated by CleverAgents Bot
Supervisor: Epic Planning | Agent: epic-planner

## Background Part of Epic #5178 (Cost & Session Budget Enforcement). Implements the `CostTracker` service that tracks LLM API spending per session and per plan, enabling budget enforcement and cost reporting. ## Expected Behavior - `CostTracker.record_usage(session_id, plan_id, tokens_in, tokens_out, model)` records usage - `CostTracker.get_session_cost(session_id)` returns total cost for a session - `CostTracker.get_plan_cost(plan_id)` returns total cost for a plan - Cost stored in SQLite database at `<data-dir>/costs.db` - Cost calculation uses model-specific pricing from configuration ## Subtasks - [ ] Define `CostRecord` model with usage fields - [ ] Implement `CostTracker` service with SQLite persistence - [ ] Add model pricing configuration to `Settings` - [ ] Implement cost calculation per model (input/output token pricing) - [ ] Write Behave unit tests for cost tracking ## Definition of Done - [ ] Cost tracking works for all LLM providers - [ ] Per-session and per-plan cost queries work - [ ] Cost persists across CLI invocations - [ ] All nox stages pass - [ ] Coverage >= 97% ## Metadata - **Branch**: `feat/v3.6.0/cost-tracker` - **Commit Message**: `feat(budget): implement CostTracker service for LLM spending tracking` - **Milestone**: v3.6.0 - **Parent Epic**: #5178 --- **Automated by CleverAgents Bot** Supervisor: Epic Planning | Agent: epic-planner
HAL9000 added this to the v3.6.0 milestone 2026-04-09 04:03:56 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: High — A2A module rename and cost tracking are required for v3.6.0 milestone
  • Story Points: 5 (L) — substantial refactoring/implementation work
  • MoSCoW: Must Have — A2A standardization is required for spec compliance
  • Assignee: HAL9000 — default assignment to maintain velocity

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: High — A2A module rename and cost tracking are required for v3.6.0 milestone - **Story Points**: 5 (L) — substantial refactoring/implementation work - **MoSCoW**: Must Have — A2A standardization is required for spec compliance - **Assignee**: HAL9000 — default assignment to maintain velocity --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 self-assigned this 2026-04-09 04:04:11 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#5248
No description provided.