Overview
After implementing actual LLM calls in execute_task(), we need to track token usage for cost monitoring and metrics.
Current State
File: codeframe/agents/worker_agent.py line 98
# TODO: Add token tracking after LLM call (see docstring example)
Expected Behavior
After each LLM API call:
- Extract
input_tokens and output_tokens from response
- Record token usage via
MetricsTracker.record_token_usage()
- Store in database with task_id, agent_id, model_name, timestamp
- Calculate cost using MODEL_PRICING constants
Implementation Requirements
- Use the pattern shown in the docstring (lines 82-93)
- Call
MetricsTracker.record_token_usage() after each API call
- Handle cases where usage info is missing (graceful degradation)
- Support multiple models (Sonnet 4.5, Opus 4, Haiku 4)
Acceptance Criteria
Priority
P1 - Critical: Required for cost monitoring and preventing budget overruns.
Dependencies
References
- Docstring example: worker_agent.py lines 82-93
- MetricsTracker: codeframe/lib/metrics_tracker.py
- User Documentation: CODEFRAME_USER_DOCUMENTATION.md lines 299-304
Overview
After implementing actual LLM calls in
execute_task(), we need to track token usage for cost monitoring and metrics.Current State
File:
codeframe/agents/worker_agent.pyline 98# TODO: Add token tracking after LLM call (see docstring example)Expected Behavior
After each LLM API call:
input_tokensandoutput_tokensfrom responseMetricsTracker.record_token_usage()Implementation Requirements
MetricsTracker.record_token_usage()after each API callAcceptance Criteria
Priority
P1 - Critical: Required for cost monitoring and preventing budget overruns.
Dependencies
References