Files
crewAI/docs/en/concepts
Lucas Gomide c4476366ff fix: aggregate token usage across all LLM calls
`flow.kickoff().token_usage` only returned the last @listen method's
`CrewOutput.token_usage`, so multi-crew flows under-reported by a
factor of N and bare `LLM.call(...)` invocations were ignored
entirely. SDK totals therefore disagreed with the CrewAI Enterprise UI
(Wharf), which aggregates every LLM span.

Add a new `flow.usage_metrics` property that wires an
`LLMCallCompletedEvent` listener for the duration of `kickoff_async`.
The listener scopes to the active flow via the `current_flow_id`
contextvar (the event bus copies the context at emit time, so the
value the handler sees is the one set when the LLM call fired) and
normalizes the provider-specific usage dict into a `UsageMetrics`.
This covers every LLM call inside the flow — crew-led, tool-led, and
bare `LLM.call(...)` — and matches the UI totals 1:1.
2026-06-11 13:29:38 -03:00
..
2026-01-05 15:30:21 -08:00
2025-09-05 17:40:11 -04:00
2025-11-24 16:51:28 -05:00
2026-02-15 04:57:56 -03:00
2025-09-05 17:40:11 -04:00
2025-09-05 17:40:11 -04:00
2026-02-12 10:55:40 -05:00
2025-09-05 17:40:11 -04:00