mirror of
https://github.com/usestrix/strix.git
synced 2026-08-21 18:52:47 +02:00
fix: ensure LLM stats tracking is accurate by including completed subagents (#441)
This commit is contained in:
@@ -799,17 +799,25 @@ class Tracer:
|
||||
)
|
||||
|
||||
def get_total_llm_stats(self) -> dict[str, Any]:
|
||||
from strix.tools.agents_graph.agents_graph_actions import _agent_instances
|
||||
from strix.tools.agents_graph.agents_graph_actions import (
|
||||
_agent_instances,
|
||||
_completed_agent_llm_totals,
|
||||
_agent_llm_stats_lock,
|
||||
)
|
||||
|
||||
with _agent_llm_stats_lock:
|
||||
completed_totals = dict(_completed_agent_llm_totals)
|
||||
active_agents = list(_agent_instances.values())
|
||||
|
||||
total_stats = {
|
||||
"input_tokens": 0,
|
||||
"output_tokens": 0,
|
||||
"cached_tokens": 0,
|
||||
"cost": 0.0,
|
||||
"requests": 0,
|
||||
"input_tokens": int(completed_totals.get("input_tokens", 0) or 0),
|
||||
"output_tokens": int(completed_totals.get("output_tokens", 0) or 0),
|
||||
"cached_tokens": int(completed_totals.get("cached_tokens", 0) or 0),
|
||||
"cost": float(completed_totals.get("cost", 0.0) or 0.0),
|
||||
"requests": int(completed_totals.get("requests", 0) or 0),
|
||||
}
|
||||
|
||||
for agent_instance in _agent_instances.values():
|
||||
for agent_instance in active_agents:
|
||||
if hasattr(agent_instance, "llm") and hasattr(agent_instance.llm, "_total_stats"):
|
||||
agent_stats = agent_instance.llm._total_stats
|
||||
total_stats["input_tokens"] += agent_stats.input_tokens
|
||||
|
||||
Reference in New Issue
Block a user