[BUG] LiteLLM path reports 0 cached and reasoning tokens in the usage summary

Aperta Adatta ai principianti
#9,786 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@basil-k-aji-dev ci sta già lavorando.

Dal 25/11/2026.

  • #9797 di @basil-k-aji-dev — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia dai sei punti di chiamata di _track_token_usage_internal in llm.py, da UsageMetrics.from_provider_dict in types/usage_metrics.py e da tests/test_llm_litellm_usage_events.py. Confronta il modo in cui _usage_to_dict gestisce l’utilizzo di LiteLLM con il modo in cui lo riceve il riepilogo, poi esegui i test esistenti sugli eventi di utilizzo. Il lavoro è completato quando il riepilogo riporta 4 token di prompt memorizzati nella cache e 3 token di ragionamento per la risposta LiteLLM descritta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

On the LiteLLM path, get_token_usage_summary() reports 0 cached and 0 reasoning tokens even though the usage event has them. llm.py passes the raw LiteLLM Usage object to _track_token_usage_internal, and UsageMetrics.from_provider_dict (types/usage_metrics.py) reads prompt_tokens_details only when it is a dict and reads reasoning_tokens only at the top level. In LiteLLM the details are pydantic objects (PromptTokensDetailsWrapper, CompletionTokensDetailsWrapper), so both counts are lost. _usage_to_dict (whose docstring says it mirrors _track_token_usage_internal) flattens them correctly for the event.

Steps to Reproduce
  1. Build a hermetic ModelResponse with usage carrying prompt_tokens_details={"cached_tokens": 4} and completion_tokens_details={"reasoning_tokens": 3} (as in tests/test_llm_litellm_usage_events.py).
  2. Run it through the LiteLLM call path.
  3. llm.get_token_usage_summary().cached_prompt_tokens is 0.
Expected behavior

cached_prompt_tokens == 4 and reasoning_tokens == 3.

Screenshots/Code snippets

Usage under-reports cache hits and reasoning tokens for every model on the LiteLLM fallback.

Evidence

Code reading of llm.py (six _track_token_usage_internal call sites) and types/usage_metrics.py at 97f2424. I can send a fix in llm.py (passing the flattened usage) with a test in the existing usage-events test file.

Operating System

Linux (Debian-based)

Python Version

3.12

crewAI Version

1.15.45 (origin/main at 97f2424)

crewAI Tools Version

Not relevant

Virtual Environment

uv

Lingua principale
Python
Stelle
61.2k
Fork
9.2k
Merge medio
1g 14h
PR unite (30g)
180

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crewAIInc/crewAI

Tutte le issue di crewAIInc/crewAI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.