Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#24 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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

  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.
Lingua principale
Python
Stelle
33
Fork
7
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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

Tutte le issue di mozilla-ai/tinyagent

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.