Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

trace.cost stays zero because LLM spans never record provider cost

Đang mở
#24 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/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, observability

Hướng nghiên cứu

Look at the after_llm_call function in the codebase to see how LLM spans are created and how token usage is recorded. Examine the any-llm library's CompletionUsage class to understand what cost data is available from providers. The goal is to add logic to calculate and set gen_ai.usage.input_cost and gen_ai.usage.output_cost on spans, ensuring trace.cost sums correctly. Start by running a test agent and printing trace.cost to confirm the bug.

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

Mô tả

What happened

AgentTrace.cost is part of the public trace API. The README tells callers to print trace.cost after agent.run(...). On current main, that total is always 0.0 for a normal completion.

after_llm_call copies response.usage.prompt_tokens and response.usage.completion_tokens onto the call_llm span as gen_ai.usage.input_tokens and gen_ai.usage.output_tokens. AgentTrace.cost then sums gen_ai.usage.input_cost and gen_ai.usage.output_cost across those spans. Nothing writes those cost attributes, so the sum stays 0.

What I expected

A completed run should report the provider's dollar cost for the input and output tokens when the provider makes that cost available.

What blocks that today

any-llm's CompletionUsage only exposes prompt_tokens, completion_tokens, total_tokens, and the token-detail breakdowns. There is no cost field to copy from the completion response onto the span.

Request

Please help find how a provider's cost can be returned dynamically through any-llm, and then written onto gen_ai.usage.input_cost and gen_ai.usage.output_cost so trace.cost reflects it. I am not proposing a bundled model price list inside TinyAgent. Unknown models, and responses that do not include a provider cost, should stay at 0 rather than being guessed.

I checked existing issues and pull requests for "cost" and did not find one tracking this.

How to reproduce

  1. Run an agent against any provider whose completion usage has token counts and no cost fields.
  2. Print trace.cost.
  3. input_cost, output_cost, and total_cost are 0.0, while trace.tokens is non-zero.
Ngôn ngữ chính
Python
Star
33
Fork
7
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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 mozilla-ai/tinyagent

Tất cả issue của mozilla-ai/tinyagent

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.