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

Đang mở Phù hợp với người mới
#9,786 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@basil-k-aji-dev đang làm issue này rồi.

Từ ngày 25/11/2026.

  • #9797 của @basil-k-aji-dev — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với sáu vị trí gọi _track_token_usage_internal trong llm.py, UsageMetrics.from_provider_dict trong types/usage_metrics.py và tests/test_llm_litellm_usage_events.py. So sánh cách _usage_to_dict xử lý mức sử dụng của LiteLLM với cách bản tóm tắt nhận dữ liệu đó, rồi chạy các bài kiểm thử sự kiện sử dụng hiện có. Công việc hoàn tất khi bản tóm tắt báo cáo 4 token prompt được lưu vào bộ nhớ đệm và 3 token suy luận cho phản hồi LiteLLM được mô tả.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
61.2k
Fork
9.2k
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
180

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của crewAIInc/crewAI

Tất cả issue của crewAIInc/crewAI

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.