[Feature Request] Mitigate exponential token consumption & add token budget guardrails

Aberta
#2,468 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 3 dias

Ninguém assumiu esta issue ainda.

  • #2482 de @juniorhillory-creator — fechado sem integrar

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
35/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
ai-infra-agents

Direção de pesquisa

The request names no files, tests, or entry points. Start by locating where task context and tool outputs are added to conversation history, then trace how token usage is tracked. Done means the team has defined and implemented the requested budget pause, output truncation, and targeted edit behavior, with tests covering those flows.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

enhancement

Is your feature request related to a problem? Please describe.
When running multi-step agentic tasks (like a 10-step debugging loop), token consumption scales exponentially due to the sliding window context. By step 5 or 6, the agent is re-sending the system prompt and all previous tool outputs (like massive linter errors or read_file contents), which drastically inflates API costs and quickly eats up the context window.

Describe the solution you'd like
To make agentic loops more sustainable, I suggest implementing a few context-management guardrails:

  1. Hard Token Budgets / Limits: Add a UI setting to set a maximum token budget per task (e.g., "Pause agent if task exceeds 100,000 tokens"). If the loop hits this, it pauses and asks the user if they want to summarize the context or continue.
  2. Raw Output Truncation: Automatically truncate or summarize massive terminal outputs (like npm error logs or large read_file payloads) before injecting them back into the context history.
  3. Targeted Diff Enforcement: Provide a built-in strict mode (or update system instructions) that heavily penalizes full-file rewrites via write_file and enforces targeted edits via edit_file to save on expensive output tokens.

Describe alternatives you've considered
Currently, my only workaround is to manually kill the task when the history gets too long and start a fresh session, or route repetitive tasks to my local Ollama models to avoid API costs.

Additional context
When the agent rewrites large files, it not only burns output tokens but also frequently busts the API prompt cache for subsequent turns. Better context pruning would keep cache hit rates higher and significantly reduce user costs.

Linguagem predominante
TypeScript
Estrelas
2k
Forks
301
Merge médio
3d 14h
PRs com merge (30d)
103

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de Zoo-Code-Org/Zoo-Code

Todas as issues de Zoo-Code-Org/Zoo-Code

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.