trace.cost stays zero because LLM spans never record provider cost
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
- Run an agent against any provider whose completion usage has token counts and no cost fields.
- Print
trace.cost. input_cost,output_cost, andtotal_costare0.0, whiletrace.tokensis 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mozilla-ai/tinyagent
-
Running an agent mutates the caller-provided message listCó thể đã có người làm @cyyecao-lappland đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mozilla-ai/tinyagent#27 ·
-
Add Python 3.14 supportCó thể đã có người làm @barredterra đã nhận 121 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
mozilla-ai/tinyagent#16 ·
-
Invalid JSON tool arguments abort the run or prematurely return a final-answer errorCó thể đã có người làm @cyyecao-lappland đã nhận 19 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
mozilla-ai/tinyagent#29 ·
-
`uses_openai` gateway prefix is unreachable since any-llm retired the `gateway` providerCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
mozilla-ai/tinyagent#23 · 2 bình luận ·
-
`import tinyagent` raises NameError with mcp >= 2.0Có thể đã có người làm @tonycoder-hub đã nhận 24 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
mozilla-ai/tinyagent#22 ·
Tất cả issue của mozilla-ai/tinyagent
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Bump zizmor to 1.31.1+Đang mởgithub_actions
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
collective/icalendar#2003 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openzim/python-scraperlib#360 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
volcengine/OpenViking#6445 ·
Maintainer thường phản hồi trong vòng 1 ngày