Contents · 17 min read
On 2026-12-04, Google added mid-conversation system instructions and tool changes in preview to the Gemini API through the Interactions API (v1beta, Gemini 4 models). A system_input step goes directly before user_input in a continued session. It carries the same authority as the top-level system instruction and takes precedence over user messages, while earlier turns stay cached; added_tools adds function definitions and removed_tools removes them. Here is the request shape, abridged from Google's example:
{
"type": "system_input",
"content": [{ "type": "text", "text": "This account is under billing review. Explain that refunds are paused and offer to escalate." }],
"removed_tools": [{ "type": "function", "name": "issue_refund" }],
"added_tools": [{ "type": "function", "name": "create_escalation_ticket", "description": "Escalate a billing review issue to support." }]
}
Why does adding or removing a tool mid-session need a new API surface at all? Because tool definitions live at the front of the prompt. Giving a model a tool means serialising its schema into the input, and every way of doing that pays three costs:
- Cache: where a definition lands determines whether the provider can reuse cached prefix computation or must reprocess every turn after the change.
- Context: how many definitions are loaded determines token overhead up front and affects how reliably the model selects the right tool.
- Contract: whether a tool call is checked against a declared schema before execution determines when parameter errors get caught.
What follows starts with native function tools and how the 2026 vendor APIs move changes to the tail, then examines two special forms (MCP and the shell), fixed-stage workflows, and compaction as the point where the prefix can be rebuilt.
Tools sit up front
A tool definition is part of the prompt prefix, so where it lands decides what the cache can reuse. Model APIs flatten tools, instructions, and conversation history into a single token sequence before inference begins. Anthropic's prompt caching documentation states the exact ordering: "Cache prefixes are created in the following order: tools, system, then messages." Google notes the same layout on Gemini: tool declarations sit at the start of the prompt, so changing the top-level tools list between turns breaks the prompt cache.
This behaviour follows directly from causal attention. In a transformer, each token's keys and values depend on every token that precedes it in the sequence. A key-value cache can therefore be reused only up to the first changed token; every token after that edit must be computed again from scratch.
The price gap is large. Under Anthropic's caching rules, modifying tool definitions invalidates the entire cache. Because Anthropic prices cached reads at 0.1× the base input price, invalidating the prefix turns a discounted read into a full-price pass over the whole transcript.
Consider a session with roughly 900 tokens of system prompt and tool definitions, followed by roughly 50,000 tokens of conversation history accumulated over twelve turns. Adding a new tool to the top-level tools list edits the request near token 900, forcing the provider to reprocess roughly 50,000 tokens of history even though none of those twelve turns changed. Appending that same tool definition after the history instead leaves the first 50,900 tokens intact in the cache, so the model only processes the newly appended tokens.
In a short single-turn request, prefix invalidation barely registers. In a multi-turn agent loop that replays its transcript on every step, putting mutable state ahead of stable history multiplies both input cost and latency. That placement constraint is why changing tools mid-run was an architectural problem rather than a minor SDK detail.
The figure runs that example four ways. Editing the list is the case above. Appending the tool after the history, or letting the model load it through tool search, processes only the new tokens. Compaction rebuilds the prefix anyway, so the tool can be declared at the head at no extra cache cost; that turn costs more, but every later turn reads a prefix about 35,000 tokens shorter. Costs are relative to the same turn without a new tool.
Adding one tool to a twelve-turn session. Token counts are illustrative.
Change at the tail
Until 2026 you could keep the prompt cache or change the tool set mid-session, not both; the vendors' answer is to declare at the head and change at the tail. When an agent needed new capabilities after a session started — because a user signed in, an approval arrived, or a task shifted — every workaround before native tail-append APIs forced you to absorb at least one of the three costs.
Before native support
- Declare everything up front. Putting every possible tool in the initial list keeps the prefix static, so the cache holds, but it pays the context cost and hurts tool selection. In a November 2025 engineering post, Anthropic reported that five MCP servers totalling 58 tools used about 55K tokens before the conversation started, with wrong tool selection and wrong parameters as the most common failures; adding tool search raised Opus 4's accuracy on Anthropic's MCP evaluations from 49% to 74%.
- Mask, don't remove. In July 2025, Manus advised against adding or removing tools mid-iteration because that invalidates the cache, choosing instead to mask token logits during decoding, with consistent name prefixes such as
browser_andshell_to restrict selectable groups. Masking preserves the cache and keeps native schemas, but it requires control over decoding and still pays the full context cost because every tool remains declared up front. - Rules in a user message. Putting new rules inside a later user message leaves earlier turns untouched and preserves the cache. As Google notes, however, instructions placed in a user message "don't carry the same weight as your top-level system instructions and allow users to try and imitate them" — and text cannot register a callable tool.
- A proxy or a subagent. A proxy exposes a fixed
search_toolsand a genericcall_tool(name, args)to keep the prefix stable, but it returns schemas as text, so the call is no longer a native, schema-checked tool call: it pays the contract cost. Handing work to a subagent with its own tool list preserves the parent's prefix and native schemas, at the cost of a handoff and extra turns.
Append-only changes
All three vendors now keep the initial declaration fixed and append changes later in the transcript. Anthropic's tool search (2025-11-24) keeps tools marked defer_loading out of the prefix and appends a definition inline when the model finds it, so "the prefix is untouched." Anthropic's mid-conversation system messages let the harness add or remove tools with tool_addition and tool_removal blocks (beta since 2026-07-24; since 2026-09-22 a whole MCP toolset can be defined inside the message) while the tools array never changes. OpenAI's tool_search (GPT-5.4 and later) injects discovered tools at the end of the context window, and a developer-role additional_tools item makes tools available from that point on. Gemini's system_input is the latest of the set.
Three questions separate them: who adds the tool, whether the change can happen inside a tool loop, and whether MCP tools are covered.
| Vendor | Mechanism | Who adds it | Inside a tool loop | MCP tools |
|---|---|---|---|---|
| Anthropic | ||||
| Anthropic | Tool search | Model | Yes | Yes |
| System message | Harness | Yes | Yes | |
| OpenAI | ||||
| OpenAI | Tool search | Model | Yes | Yes |
| additional_tools | Harness | Not documented | Not documented | |
| Gemini | ||||
| Gemini | system_input | Harness | No | No |
Changing tools at the tail, as documented in December 2026.
The first distinction is pull versus push. Tool search is pull-based: the model decides it lacks a capability, queries for matching definitions, and receives the schemas inline. Harness messages — Gemini's system_input, Anthropic's role: "system" tool blocks, and OpenAI's additional_tools — are push-based, letting the harness announce an external change of state that the model could not know to request.
The second distinction is where in the loop a change may happen. On Gemini, system_input cannot be sent "during a function-calling loop (when returning a function_result step). Wait until the next user_input turn." A Gemini harness therefore cannot run a search-and-inject loop inside a single autonomous turn; it must wait for the next user message. Gemini also restricts added_tools and removed_tools to custom function tools: "MCP servers and built-in tools (like Google Search or code execution) aren't currently supported." On Anthropic, a system message can go immediately after a user message carrying tool_result blocks, so the harness can swap tools mid-loop before the model plans its next call.
What appending costs
Appending keeps the prefix warm, but every appended block still occupies the context window. On Gemini, "Each system_input step stays in context for the rest of the conversation and can't be removed," and when instructions conflict the model favours the most recent one, so repeated updates accumulate over a long run. Anthropic's turn-scoped system messages (beta, 2026-09-01) limit that buildup for temporary notes by rendering a reminder only until the next user message — "Per-turn reminders don't accumulate and don't invalidate the prompt cache" — while persistent tool changes remain part of the transcript. In short, appending at the tail moves the bill from the cache to the context window, and compaction has to settle it later.
MCP tools are borrowed
To the model an MCP tool is just a function definition; what is different is that someone else writes it and the host decides how it enters the prompt. When you call a model API directly, you own the schemas, their ordering, and when they load. The Model Context Protocol splits those roles between an external server and a host application, which changes how cache, context, and contract behave.
An MCP server exposes its tools at runtime through tools/list, so the host does not know what exists until it connects, and the returned list can differ per user. When the tool set changes during a session, the server sends notifications/tools/list_changed and the client is expected to call tools/list again. In 2026 there were public reports that popular clients ignored list_changed mid-session, and even when a client honours the notification, re-injecting a changed list at the front of the prompt breaks the cache anyway.
Because the protocol does not dictate prompt assembly, different hosts handle the same server in different ways:
- Antigravity documents that discovered MCP tools are "automatically added to the agent's toolset and listed in the system prompt".
- Claude Code defers MCP tool definitions by default through tool search, loading names at startup and full definitions on demand.
- GitHub Copilot CLI skips tool search when there are fewer than about 30 tools.
There is also a split between provider-hosted and client-side MCP. In provider-hosted MCP, such as Anthropic's mcp_toolset or OpenAI's MCP tool, the model provider fetches the tool list directly; in client-side MCP, a local host such as Claude Code, Antigravity, Codex, or Cursor fetches tools/list and passes the tools to the model API as ordinary function tools. My reading is that Gemini's exclusion of MCP servers from added_tools concerns provider-side MCP; as far as the docs show, a client-side host that has already converted MCP tools to function definitions could pass them through added_tools, though Google does not state this.
Those host differences shape how you have to design an MCP server. On a remote MCP server I owned for a quantitative-research product in a previous role, users connected from several coding-agent hosts and the server reached about sixty tools at its largest. Because I could not control how any given host injected or deferred schemas, four design choices mattered:
- Tools per task, not per endpoint. Each tool represented a user-level task rather than a raw backend endpoint, keeping the total tool count manageable for hosts that load the full list into context.
- Names written for search. I used natural-language tool names instead of a short product prefix because hosts discover deferred tools by searching names and descriptions. Manus-style prefixes assume you control token decoding, which an MCP server author does not.
- A stable, per-user list. The server returned tools in a fixed order, filtered by the user's OAuth scopes. Different users received different prefixes, but each user's prefix stayed stable within a session, so the host could keep its cache intact.
- No search tool on the server. Tool discovery belongs to the host, through tool search, deferred loading, or allowed-tool subsets; a server-side search meta-tool would return schemas as text and force a call-by-name proxy. Search over business data stayed inside the business tools.
Ownership affects the contract as much as the cache and the context. On that server, expensive operations were split into validate and submit steps, and parameter constraints lived in the JSON schema and in server-side validation rather than in prose instructions. Even valid JSON Schema can fail across the host boundary: one tool's input schema used oneOf, a particular host's connector version did not handle it correctly, and valid requests were rejected in production. The fix simplified the published schema and kept the cross-field checks in server-side validation. With MCP, the host's schema handling is part of the contract.
Shell skips the schema
The shell solves cache and context by collapsing every tool into one generic definition, and pays with the contract. Instead of declaring dozens of narrow functions at the front of the prompt, the agent receives a single shell tool whose schema never changes across the session.
The mechanics line up cleanly with prompt caching. One fixed shell definition sits at the front of the prompt, keeping the prefix stable. New abilities arrive when the model reads documentation or local scripts, which enter at the tail of the conversation as ordinary tool output. Skills follow the same pattern — Antigravity documents this, and Claude's skills work the same way — by injecting only each skill's name and description up front and loading the full body only when the model uses it. Anthropic's code execution with MCP formalises the pattern further by presenting MCP servers as code APIs, so the agent writes code, loads only what it needs, and filters data before it reaches the model.
What this pattern gives up is upfront validation. Checking moves from a schema before execution to the runtime after a command runs, so how much the shell costs depends on how cheap, fast, and informative the runtime's feedback is.
I saw both ends of that spectrum in development traces from a quantitative-finance agent benchmark I worked on, introduced in an earlier note. Agents ran simple loops inside a Docker sandbox, with a fixed tool list exposed through the benchmark's MCP server, including shell_exec, file tools, and a LEAN backtest tool. The traces cover 227 development sessions from March–April 2026 across four models from two vendors, with mixed task and harness versions, so they are not a controlled evaluation. Running Python through the shell worked well without any parameter schema: of 2,426 Python runs, 9.9% exited non-zero, and of 230 failures followed by another Python run within three steps, 194 (84%) succeeded on the next try. Tracebacks came back complete, and a retry cost nothing.
LEAN backtests — C# algorithms run on QuantConnect's open-source engine, with a budget of five trials per session — showed the opposite. Across 169 trials in 45 sessions, 24.9% did not succeed (18 compile errors, 21 runs with no trades, and 3 runtime errors), and 19 of the 45 sessions hit the five-trial cap. A compile error used up one of those five trials. The compile errors were API-contract mistakes involving types, members, or arguments that did not exist or did not match. Most other failures came from the sandbox's environment rules — entry point not found, missing data directory, no currency conversion path — which no input schema could express, because the tool's argument was a file path and the real parameter was the C# source. For 13 of the 24 runtime and no-trade failures, the tool result did not even contain the cause.
The figure puts the two side by side: how often each failed, what a retry cost, and what happened next.
| Python through the shell2,426 runs | LEAN backtests169 trials | |
|---|---|---|
| Failed | 9.9% | 24.9% |
| A retry costs | Free, with a full traceback | One of five trials |
| Outcome | 84% fixed on the next run | 19 of 45 sessions hit the cap |
Same sandbox, two kinds of code. One square is 1% of attempts. Development traces from four models, not a controlled evaluation.
My judgment from those traces is that taking errors from the engine was right, because the engine is the source of truth; the flaw was that the only check sat behind the trial budget. When an action is expensive or depends on niche environment rules, the contract has to arrive before the cost — through a template that states the environment's rules and a preflight check that costs nothing. A later revision of the harness added a template tool and a preflight check that does not consume a trial; all the traces predate it, so its effect is unmeasured.
Stages fix the tools
When you own the workflow, you can avoid changing tools mid-run altogether. Dynamic tool loading assumes a single long-running conversation that has to handle every phase of a job. If you control the orchestration, splitting the workflow into discrete stages lets each stage carry a small, static tool declaration from start to finish.
That is how I structured ARA (arxiv-research-agent), a public LangGraph research agent over arXiv papers. Only one stage runs a model-driven tool loop — a researcher with two tools, arXiv search and lookup by id, capped at 8 calls per turn — while every other stage is a single call with structured output. The project's design rule records the reason: "Each stage keeps a fixed tool list, schema and reasoning effort; changing any of them breaks the cached prefix." With two tools and a fixed schema, the researcher stage pays almost no context overhead, keeps full schema validation, and never invalidates its own prefix.
The limitation is flexibility once a stage is running. If the researcher needs a new capability partway through a loop, a fixed-stage design has no built-in way to grant it. Adding a tool in the middle of research means either splitting the graph to add another stage with an explicit handoff, or adopting a mid-conversation tool change so the active loop can expand without restarting.
Compaction is a reset
Appending moves the cost from the cache to the context, and compaction is the one point where the front of the prompt can be rewritten cheaply. Every tool definition fetched through tool search, and most instructions pushed at the tail, remain in the transcript. Over a long session, those appended updates gradually bring back the context bloat that deferred loading was meant to avoid.
My reasoning — rather than a documented vendor workflow — is that compaction changes the cost of editing the prefix. When a session compacts by replacing older turns with a summary, the cached prefix covering that history is invalidated and has to be computed again anyway. Because you are already paying to rebuild the cache at that boundary, compaction is the moment to fold accumulated tail rules into the base system instructions, re-declare the exact tools the task currently needs, and drop tools that were withdrawn earlier. Making those edits between compactions throws away a warm cache; making them at compaction turns a necessary rebuild into a clean reset of both prefix and context.
Not every compaction strategy rewrites history. ARA's own rule is: "Conversations stay append-only. Compaction happens only at a turn boundary, by appending a summary note, never by rewriting earlier messages." On the provider side, Anthropic's compaction API (beta) does replace older turns with a summary written on the server, and when compacting on demand you send the same system prompt and tools. What happens to tools added mid-conversation after compaction is not documented on Anthropic's side, and Google's mid-conversation instructions page says nothing about compaction, so treating compaction as a tool-list reset remains an engineering pattern to verify per provider rather than a guaranteed API behaviour.
Which one to use
Choosing how to load tools comes down to two questions: who owns the prompt prefix, and how expensive a bad call is. If you own the workflow, fixing tools per stage avoids mid-run changes entirely. If the session must stay open-ended, choose between runtime feedback in a shell, pull-based tool search, and push-based mid-conversation updates, depending on whether the model or the harness knows what changed.
| Situation | Approach |
|---|---|
| Coding agent with a sandbox | Use a shell tool; keep runtime feedback fast and cheap |
| Structured agent with hundreds of tools | Defer loading and fetch schemas with tool search |
| Session state change (sign-in, approval, freeze) | Push mid-conversation system instructions and tool updates |
| Writing an MCP server | Keep a stable task-level list; let hosts handle search |
| Owning a multi-stage workflow | Fix one small tool set per stage |
Every way of giving a model a tool trades off cache reuse, context size, and upfront contract checking. Native APIs now let you push or pull tool changes at the tail without breaking a warm prefix, while the shell drops schemas to keep the prefix tiny and MCP splits ownership between server and host. Good agent architecture comes down to choosing which of those three costs your system can afford, rather than paying all three by default.
