Price tool schemas by JSON density and compute them once

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
ai

Direzione di ricerca

Start in account_tools() in src/agent/run.rs, which sums tool name, description and serialized parameter lengths, then read the chars_per_token calibration in src/context/budget.rs. Move the schema sizing into a value computed once when Core is built, and add a separate JSON density constant so prose calibration can't affect it. Done when the first-call estimate is within 8% of usage.prompt_tokens, no schema serde_json::to_string remains in run_loop, and a unit test pins the constant.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: context area: performance enhancement priority: P1

Problem

account_tools() divides the serialized schema length by chars_per_token, which is calibrated on prose and defaults to 3.5. JSON keys, quotes and type names tokenize closer to 2.5-2.6 characters per token, so the 24 schemas are booked at roughly 2.3k tokens when they cost closer to 3.3k. The undercount delays compaction until the server rejects the request or truncates it.

The same function also re-serializes all 24 schemas with serde_json::to_string on every loop iteration, which is pure allocation churn.

Evidence

  • src/agent/run.rs, account_tools(): sums name.len() + description.len() + serde_json::to_string(&tool.parameters).len() and calls estimate_char_len.
  • src/context/budget.rs: one chars_per_token for all text, calibrated from prose.
  • The schema JSON is static for the life of the process.

Proposal

Compute tool_specs_chars and tool_specs_tokens once when Core is built. Use a separate json_chars_per_token constant (2.6) or, when /tokenize is available, tokenize the serialized tools array once at startup and store the exact count. Add the fixed term to the assembled estimate instead of recomputing it. Keep prose calibration separate so it cannot move the JSON estimate.

Acceptance criteria

  • On the full profile, first-call |estimated - usage.prompt_tokens| / prompt_tokens < 0.08.
  • No serde_json::to_string of tool schemas remains inside run_loop.
  • /tokenize-capable engines use the measured count; others use the JSON constant.
  • A unit test pins the JSON density constant and the fixed-term behavior.

References

Lingua principale
Rust
Stelle
0
Fork
0
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 GotinhaAzul/LocalHarness

Tutte le issue di GotinhaAzul/LocalHarness

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.