Skip to main content
November 27, 2026

Agent Harness: The Hard Problems After the Demo

Agent Harness: The Hard Problems After the Demo

The first version of an agent harness is a loop: send messages and tool definitions, run the tool calls that come back, append the results, repeat. It fits on one screen and it works on the first task you try. Then the runs get longer, someone plugs in a cheaper model, the skills folder grows to forty files, and the bill doubles for no reason anyone can see.

None of those problems is in the model. They are in the harness, and most of them touch one thing the demo never cared about: the prompt cache. Here are six, with what the vendor docs say and the trade-off of each fix.

First, the Rule Everything Else Depends On

Anthropic's prompt caching docs say "Cache prefixes are created in the following order: tools, system, then messages," and "Changes at each level invalidate that level and all subsequent levels." A change to the tool definitions "invalidates the entire cache." The default lifetime is 5 minutes, cache writes cost 1.25 times the base input price, and cache reads cost 0.1 times (less on some newer models).

So a long agent run is cheap only while its prefix stays byte-stable. Keep that in mind for every section below: a fix that rewrites the prefix trades a correctness problem for a cost problem.

1. Context Management

A long run fills the window with tool output, and the model gets worse before it runs out of space. Anthropic's context engineering post calls this context rot: "the model's ability to accurately recall information from that context decreases." It lists three tools: compaction, structured note-taking, and sub-agents that "handle focused tasks with clean context windows" and return a summary "often 1,000-2,000 tokens" long.

Each one has a cache cost:

  • Compaction. Claude Code's prompt caching page says compaction "invalidates the conversation layer: the next request has a new, shorter history that doesn't share a prefix with the old one." The summary itself is a separate request, and the costs page warns that "compacting a large context is itself a large request."
  • Tool result clearing. The API's context editing can clear old tool results server-side. It "invalidates cached prompt prefixes when content is cleared," so the docs advise you to "clear enough tokens to make the cache invalidation worthwhile."
  • Sub-agents. A Claude Code subagent "starts its own conversation with its own system prompt and tool set," and "the parent's cache is unaffected." The parent pays only for the summary it reads back.

The harness decision is when to pay. Compact rarely and in large steps, not a little on every turn.

2. Tool Activation for Weaker Models

A long tool list hurts even frontier models. Anthropic's tool search docs say Claude's ability to pick the right tool degrades past 30 to 50 tools, and offer defer_loading: true: such tools "load only when Claude discovers them through search." The API "excludes deferred tools from the system-prompt prefix," so discovering a tool does not rewrite the cached prefix.

Weaker models fail earlier and more quietly. Our local models docs describe what happens with Akmatori's single generic tool, gateway_call(tool_name, args, instance): small models often call ssh.execute_command as if it were a tool of its own, and Ollama "drops a tool call whose name is not one of the defined tools, and returns an empty answer without an error." In our test, qwen3:30b-a3b produced a correct gateway_call in 13 of 28 requests, and the 0.6b, 4b and 8b sizes in 0 of 2 each.

The trap: the failure is dropped by the server before your harness sees it, so an alias table or a retry on the client cannot catch it. Treat an empty final answer after a tool-capable turn as a failed run, count it as its own metric, and test the actual model with your actual tool schema before you rely on it.

3. Skill Cost

Skills are cheap until you have many. The Agent Skills specification puts metadata at about 100 tokens per skill, "loaded at startup for all skills," with the body (under 5,000 tokens recommended) loaded on activation, and asks you to keep SKILL.md under 500 lines.

A worked example: 40 skills at 100 tokens each is 4,000 tokens on every request. Cached, that is cheap per turn, but the model must read all of it to pick one, and an edit to any description changes the prefix for every run.

Claude Code caps this. The skills docs say the combined description and when_to_use text "is truncated at 1,536 characters in the skill listing," and a skill with disable-model-invocation: true keeps its description out of context; the full skill loads only when invoked. Put the use case in the first sentence, because the tail may not survive.

Akmatori follows the same pattern: per the skills docs, the agent "sees the name and description of every enabled skill and reads the full instructions when a skill is relevant." Disabling a skill you do not use is a cost decision, not just tidiness. We covered how skill text ages across model versions in skills regress on model upgrades.

4. LSP: Feedback That Costs Context

A coding agent that edits files blind finds its type errors at build time. Language servers close that loop. Claude Code's code intelligence plugins give "diagnostics after edits" and an LSP tool for symbol lookup that "is read-only." The plugin "doesn't include the language server": you install the binary. OpenCode's LSP docs use diagnostics "as feedback for the agent," but LSP "is disabled by default," and the page warns that language servers "can get out of sync, use significant memory, vary by version or project, and slow down agent workflows."

Diagnostics arrive as new content after an edit, so they extend the prefix instead of rewriting it, but they add tokens on every edit. Push only errors for the file the agent just touched, not the whole project's warnings.

5. Fallback Models

Claude Code's CLI reference shows the shape: --fallback-model enables "automatic fallback to the specified model(s) when the primary model is overloaded or not available," as "a comma-separated list tried in order."

Two costs hide in that line. First, per the prompt caching page, "Each model has its own cache," so the first request on the fallback reads the whole conversation with no cache hits. Second, the fallback is usually a smaller model, and section 2 shows what smaller models do to tool calls. A fallback you never tested on your tool schema converts an outage into a run that ends with an empty answer. Run your eval set on every model in the chain.

6. Cache-Safe Role Switches

A harness often switches roles mid-run: planner to executor, investigator to reviewer. The obvious implementation swaps the system prompt or the tool list. Both rewrite the prefix.

Claude Code shows the cache-safe way. Its caching page says "Plan mode and skill loading, for example, append their instructions as conversation messages, so the cached prefix stays intact." The exception proves the rule: opusplan uses Opus during plan mode and Sonnet during execution, "so each plan-mode toggle is a model switch and starts a fresh cache." On listed newer models, the API also accepts a {"role": "system"} message appended to messages, which leaves the cached prefix alone.

For tools, keep the definitions fixed and enforce the role elsewhere. Akmatori does this with one generic tool: the model always sees gateway_call, and per the architecture docs the API server builds an allowlist from the kind of run while the MCP Gateway "refuses every tool outside it." Permission lives outside the prefix.

Decision Table

Problem Cheap fix What it breaks What to measure
Context grows Compact every turn Conversation cache, every time Cache read ratio per run
Too many tools Remove tools per role The entire cache Wrong-tool and no-tool rate
Weak tool caller Retry the request Nothing, and it rarely helps Empty answers after tool turns
Many skills Shorten all descriptions Skill selection accuracy Which skill each run loaded
No compile feedback Push all diagnostics Context budget Diagnostic tokens per edit
Provider outage Untested fallback chain Cache and tool accuracy Eval pass rate per model in chain
Role switch New system prompt System and message cache Cache writes at each switch

Checklist Before You Call the Harness Done

  1. Log cache_read_input_tokens and cache_creation_input_tokens for every request, and alert on a run whose writes jump mid-run.
  2. Keep tool definitions and the system prompt byte-identical for the whole run. Inject the date, the role and the plan as messages.
  3. Compact in large steps, and check what the summary dropped.
  4. Count empty final answers as failures, per model.
  5. Cap the skill listing and put the use case first in every description.
  6. Run the eval set on each fallback model, not only the primary.
  7. Enforce tool permissions outside the prompt, so a role change does not need a new tool list.

Conclusion

The demo proves the model can call a tool. The harness has to keep long runs readable, catch the failures weak models hide, keep skills and diagnostics within budget, survive a provider outage, and switch roles without throwing away the cache. Most of those come down to one rule: append, do not rewrite.

If your team wants AI-assisted incident workflows on a harness where tool permissions live in the gateway and not in the prompt, Akmatori helps SRE teams investigate alerts, coordinate response, and automate safe infrastructure actions. Powered by Gcore for global infrastructure reliability.

Automate incident response and prevent on-call burnout with AI-driven agents!