trace.cost stays zero because LLM spans never record provider cost
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- backend, observability
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 33
- Fork
- 7
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di mozilla-ai/tinyagent
-
Running an agent mutates the caller-provided message listForse già presa @cyyecao-lappland l’ha presa 19 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
mozilla-ai/tinyagent#27 ·
-
Add Python 3.14 supportForse già presa @barredterra l’ha presa 121 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
mozilla-ai/tinyagent#16 ·
-
Invalid JSON tool arguments abort the run or prematurely return a final-answer errorForse già presa @cyyecao-lappland l’ha presa 19 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
mozilla-ai/tinyagent#29 ·
-
`uses_openai` gateway prefix is unreachable since any-llm retired the `gateway` providerForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
mozilla-ai/tinyagent#23 · 2 commenti ·
-
`import tinyagent` raises NameError with mcp >= 2.0Forse già presa @tonycoder-hub l’ha presa 23 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
mozilla-ai/tinyagent#22 ·
Tutte le issue di mozilla-ai/tinyagent
Issue simili
-
infrastructure
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
khuisman/mcp-gee-sweet#1152 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
backroom bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ditto-assistant/ditto-subnet#3069 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
open-webui/open-webui#32901 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
0.3.3 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno