Claude API tool-use agent burns too many tokens on large documents: how to make it reuse prebuilt blocks instead of generating from scratch?
retained text
I have a C#/.NET (WPF) desktop application that draws electrical schematics for industrial control panels. It includes an AI assistant that uses the Claude API (Messages API with tool use) to build complete projects. The model calls the application’s tools, such as `inserir_componente` (insert component), `ligar` (connect), `ler_folha` (read sheet), `verificar_projeto` (check project) and `ver_pagina` (returns an image of the page). The application itself validates the wiring in code. A typical project has 20–60 pages and follows a strict drawing standard. The customer’s documents are attached as PDFs in the first request. **How it works today:** * A “coordinator” agent plans and splits the work. “Executor” agents draw groups of pages, each in its own conversation, and a “reviewer” agent checks the result. * Every call resends the system prompt, the drawing rules (\~5k tokens), the tool definitions, the PDFs and the conversation history. I use prompt caching, with `cache_control` on the system prompt and at the end of the conversation. **What I measured on a large project (one request, 240 calls):** |Part|Tokens|% of cost| |:-|:-|:-| |Cache writes|2.2 M|46%| |Output (including thinking)|421 k|35%| |Cache reads|24.3 M|20%| Each call carried about 100k tokens of context on average. **What I’ve already fixed:** 1. The cache has a 5-minute lifetime, and it expired while the coordinator was waiting for an executor to finish. I now resend the last request with `max_tokens: 0` every 4 minutes to keep it warm. 2. The context limit counted the whole prompt. With the PDFs at the start of the conversation, the agent kept “summarizing and restarting” almost all the time. The limit now counts only what the current request added. 3. I now log the usage of every call to a CSV file. **The remaining problem:** Many circuits repeat from project to project (main power supply, motor starters, local/remote control, VFDs). Even so, the model tends to draw component by component: dozens of calls, each one re-reading the context. I created “macros” (prebuilt blocks inserted by an `inserir_macro` tool) and a catalog of standard parts. I’m still not sure what the best way is to make the model reliably prefer these blocks without losing quality. **My question:** in a tool-use agent that generates large, structured documents, which techniques work in practice to make the model reuse prebuilt blocks instead of generating from scratch, so that there are fewer calls and less context to re-read? For example: * describing the macros in the tool definitions, or in a catalog the model queries on demand; * a “plan” tool that returns the list of blocks to insert; * or separating planning (done once) from execution (with minimal context). If anyone has measured the effect of this on cost, I’d like to know the order of magnitude
document fetched 2026-11-20 00:22 · canonical https://reddit.com/r/ClaudeAI/comments/1y09i3e/claude_api_tooluse_agent_burns_too_many_tokens_on