Do Custom Agent Tool Restrictions Actually Reduce Context Window Usage And Token Impact #198247
-
🏷️ Discussion TypeQuestion 💬 Feature/Topic AreaVS Code BodyHi, I have a question about how tool schemas are handled in the context window when using custom agents in GitHub Copilot (VS Code). From the documentation, I understand that:
However, it's unclear how this affects the context window in practice. My question is: If I define a custom agent with a limited set of tools (e.g. only Tool A), does this guarantee that only the schemas for Tool A are included in the model's context window, or are all tool schemas from enabled still injected into the context, with the agent only restricting usage? In other words:
I'm trying to understand whether custom agents can be used as a reliable way to reduce context window usage, Or should we always be very cautious when adding new tools. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
Hi @r-shakeri, The answer to your question: Yes, restricting the It is not just an execution barrier; it is a context filter. Using custom agents to limit tools is actually one of the most effective ways to optimise token consumption in Copilot. Here is a breakdown of how this works under the hood and why it matters. How Tool Schemas Consume ContextEvery time Copilot makes a request to the LLM, it has to tell the model which tools it can use. It does this by injecting the JSON schema for every enabled tool (including its name, description, and parameter definitions) directly into the system prompt.
Why You Should Curate ToolsRelying on custom agents to aggressively restrict tools is a highly recommended best practice for two main reasons:
SummaryYou are thinking about this exactly right! Defining a tightly scoped custom agent with only the tools necessary for its specific job is not just a security/execution restriction, it is a critical optimisation technique. You should absolutely continue being cautious about adding global tools and instead scope them tightly within specialised agents. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, That's a good question. Based on the current documentation, custom agents allow you to restrict which tools an agent can use through the My understanding is that there are two separate concerns:
The docs clearly describe the first, but I haven't found a definitive statement about the second. Because of that, I would be cautious about assuming that limiting If context efficiency is important, it would be helpful for GitHub to clarify:
Hopefully someone from the Copilot team can confirm the exact behavior. |
Beta Was this translation helpful? Give feedback.
-
|
Adding the quantitative side, since the real answer is "yes — if the client sends the filtered Each tool schema is fixed per-turn input, re-sent on every request. From measuring 79 tools across 13 MCP servers/agents, a tool averages ~123 tokens (median 103; heavier ones run 300–360). So if your custom agent actually filters the sent schemas, going from ~20 tools to ~5 should shave roughly 15 × ~123 ≈ ~1,800 tokens per turn — billed on every message, so it compounds fast. To verify whether your client truly filters (vs. just gating execution): count the input tokens with the full toolset vs. the restricted agent on an identical prompt. If the input drops, schemas are being filtered; if it's unchanged, you're only restricting usage. Anthropic's |
Beta Was this translation helpful? Give feedback.
@r-shakeri
That is a completely fair critique. You are absolutely right that the documentation frames this around model accuracy (preventing the LLM from getting confused or invoking the wrong tool) rather than explaining the underlying payload mechanics.
However, from a purely technical standpoint, restricting the
toolsarray does physically reduce the prompt size and context window usage.Because Large Language Models are stateless, they have no built-in awareness of your local VS Code environment. For an agent to know a tool exists, the Copilot client must inject the tool's complete JSON schema (its name, description, and all parameter definitions) directly into the hidden system promp…