obs(orchestration): track planner/aggregator LLM calls in session metrics (#1899)#1925
Merged
obs(orchestration): track planner/aggregator LLM calls in session metrics (#1899)#1925
Conversation
…n metrics LlmPlanner::plan() and LlmAggregator::aggregate() now return token usage alongside their result, captured immediately after each provider.chat() call. Call sites in agent/mod.rs update api_calls, prompt_tokens, completion_tokens, total_tokens, record_cost, and record_cache_usage for both operations. tasks_skipped is now incremented in the Completed graph path alongside tasks_completed. handle_status_command() shows an Orchestration section (plans, tasks completed/total, failed, skipped) when plans_total > 0. Fixes #1899.
IC-02: GraphStatus::Failed arm now mirrors Completed arm by also incrementing tasks_completed and tasks_skipped counters, so partial failures are reflected accurately in orchestration metrics. Integration test: destructure aggregate() return value to (String, Option<(u64, u64)>) to match updated LlmAggregator::aggregate signature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LlmPlanner::plan()andLlmAggregator::aggregate()now returnOption<(u64, u64)>(prompt_tokens, completion_tokens) alongside their existing resultagent/mod.rsuse the returned usage to incrementapi_calls,prompt_tokens,completion_tokens,total_tokens, cost, and cache stats in the sharedMetricsCollectortasks_skippednow incremented in bothGraphStatus::CompletedandGraphStatus::Failedarms offinalize_plan_execution/statusshows anOrchestration:block (plans, tasks completed/failed/skipped) whenorchestration.enabled = trueandplans_total > 0aggregate()return typeRoot cause
api_callswas only incremented innative.rsandlegacy.rs(the main agent loop LLM call sites).LlmPlanner::plan()andLlmAggregator::aggregate()calledchat_typed()directly, bypassing those paths. Token usage and cost for orchestration sessions were completely untracked.Design note
The architect's initial approach (reading
last_usage()fromself.providerafter planner/aggregator return) was rejected:AnyProvider::clone()creates a newMutex<Option<(u64,u64)>>initialized toNone— the clone used by planner/aggregator writes to its own independent mutex. Fix: return usage data directly fromplan()/aggregate().Follow-up
chat_typed()retry loops overwritelast_usage— only the final attempt's tokens are captured. Pre-existing limitation of thelast_usage()API, not introduced here.Closes #1899