The author’s thoughts. The idea that a gate is an external part and stands behind the agent’s context border, and the conclusions from it, belong to the author: a gate belongs at a bounded-context border; one narrow set of MCP functions both saves context and limits permissions; gates lengthen autonomous work. No source words it as “a gate behind the context border”. Nobody has measured the lengthening of autonomous work: the autonomy section offers a calculation and cases, not a sample-based experiment. Sources confirm separate links, and next to them stand an address and the exact phrase.
an intake postmachine · agent · personbounded contextpermissions and functionshow gates are bypassedIn short: what a gate is and why an agent needs one
The road of the work: the agent walks through its own context step by step, the work reaches, through MCP, a gate that stands in another context. The gate answers “accepted”, “back with an error” or “not sure, a person decides”.
What it is. A gate stands between the agent’s work and the word “done”. The agent brings a result, and the check gives one of three answers: accepted, not accepted (errors go back to the agent) or not sure (a person decides). The post says “done”. If the check fails, the work goes no further: not to the next step, not into a merge, not to the user. A gate is an external part: a control point cannot stand in the same bounded context as the agent, or it shares the agent’s blind spots. So it stands behind a separator: behind an MCP server, in a client hook or in another process. Very little crosses this border in either direction: a short result there, a short answer back, everything else is closed. A gate works because checking is usually easier than doing. This is kin to the “P versus NP” question of complexity theory: finding a solution may be hard, checking a finished one is fast. For agents this is only an analogy: a check is not cheap for every task, and where it is not, the gate leans on a person.
Why. The first reason is quality: an agent grades its own work poorly, and an independent check sees what it missed. The second is autonomy: an error caught at a step does not travel through the next twenty steps, so the agent can work longer without a person. The third is a person’s attention: they look only at the disputed cases the gate handed over.
Where to put it. Outside the agent and outside its context: in a client hook or in server permissions behind MCP, and not in instruction text the agent may ignore. The agent itself works inside a small bounded context: there a check is finite, the change is small and the set of MCP functions is narrow. These places are covered in the “Border” and “MCP” sections.
Where the word comes from: from code inspection to gates for agents
The word “gate” came from product management, factories and software engineering. Below are four points on the way, and each carries an idea that agent gates inherited.
Code inspection, Stage-Gate, a gate on new code, and gates for agents.
Two more ideas came from factories. Deming’s third of fourteen points says to stop depending on inspection at the end and to build quality into the product from the start. In its jidoka system Toyota makes equipment stop at once when it detects an abnormality. An agent gate joins both ideas: the check stands as early as possible and can stop the work.
Why an agent does not check itself
The first thing research shows: an agent overrates its own work. Anthropic found that separating the agent doing the work from the agent judging it is a strong lever. They also note that out of the box Claude is a poor reviewer and had to be tuned for strictness.
The most detailed measurement is a preprint by Park and Choi (July 2026, a draft pilot). The same agent ran six improvement cycles, and only whoever closes the feedback loop changed, that is, the judge of the result: the agent itself, a strong judge inside the loop, or an external check that sees the real outcome. The chart shows the final score of each variant.
The agent’s self-grading rolled back what had been achieved by 19%, and the external check gave the maximum. A pilot: one model, one task, three repeats.
What stands behind the numbers. The agent called all 54 cycles an improvement, although in 56% of them the real change was zero or negative: self-grading turned into “accept everything”. Even the strong judge inside the loop accepted real regressions in 44% of cases and rejected 38% of real improvements. The authors explain the gap this way: the gap is set by what the judge relies on, and the judge’s intelligence does not affect it. A judge inside the loop sees only what the agent showed it. An external check looks at the real outcome.
Anthropic reached the same conclusion with its C compiler (a case described by Anthropic itself): 16 agents, about 2,000 sessions and about $20,000. The author named a nearly perfect verifier as the main condition. The same article warns. Tests pass and the work is not done: this happens while a check is not deterministic. A deterministic check on the same data always gives the same verdict, like running tests or a linter. A judge model’s answer may differ from run to run, so the judge adds to the check program and does not replace it.
One more observation from the pilot: one bit was enough for the external check. A verdict “accepted” or “rejected” without any explanation scored 110.0 against 113.0 with a full write-up. So a gate does not have to give its reason: a yes or a no is enough.
Three kinds of check at a gate
An intake post can hold a check of three kinds. They differ in speed, price and what they can see, so in practice several are placed in a row: a cheap fast one first, a pricey rare one last.
Left to right the check gets smarter, slower and pricier.
| Kind | What it sees | Example | Weak spot |
|---|---|---|---|
| A machine | anything written as a rule: tests, types, linter, build, coverage | Sonar for agents: new-code coverage at least 80%, duplication at most 3%, no new bugs or vulnerabilities | sees no meaning: sensors catch misdiagnosis, needless complexity and misread tasks unreliably |
| A reviewing agent | meaning by criteria with a threshold | Anthropic: below the threshold on any criterion, the stage fails; Spotify’s judge vetoes about a quarter of sessions | pricier, needs tuning for strictness, and it errs too |
| A person | risk, intent, consequences | GitHub: draft PRs from the agent are approved and merged only by a human | gets tired and used to approving |
A machine. Sets the lower level. For code written by agents Sonar requires six conditions: no new bugs, vulnerabilities or maintainability issues above a threshold, new-code coverage of at least 80%, duplication of at most 3%, and no new dependency risks. The last condition appeared because of agent behaviour: they may install packages without vetting. For the split of checks into guides and sensors see the article “Harness engineering in practice”: a gate is a sensor that has the right to stop the work.
A reviewing agent. At Anthropic each criterion had a hard threshold, and if even one fell below it, the stage failed and the agent received a detailed write-up. Before a stage the executor and the reviewer agreed a stage contract: what counts as “done”. Spotify added a judge after agents began doing extra: refactoring code outside the task and disabling flaky tests. The judge compares the change with the original request.
A person. GitHub built the human into the process itself: the agent can neither mark its PR ready, nor approve it, nor merge it. Such a gate is needed where an error is costly: money, access, other people’s data.
A gate has three answers: accepted, not accepted and “not sure”. The third hands the case to a person and shows where the check’s frame ended. Why such an answer is unavoidable for any agent code is covered in the article “Where to check an AI agent’s work”.
What gates give quality, and what it costs
The numbers below come from four separate sources: two Anthropic write-ups (24 Mar 2026 and 5 Feb 2026), engineering blogs of Stripe and Spotify, and the DORA 2025 report. No sample-based studies exist: nobody has published “with a gate and without” comparisons over hundreds of tasks, so each number serves as an example. The link next to each number shows where it comes from.
One request: an agent alone and an agent with a reviewer.
How gates lengthen autonomous work: arithmetic and a gap in the data
A language model keeps a rough sketch of the world, not the world itself. When an agent checks its steps against reality (tests, system answers) and keeps its context in order, errors are found and fixed. Work on self-correction supports this: it helps with a reliable signal from outside and sometimes hurts without one. “The longer, the better” holds only with such checking: quality drops on long input, and on some tasks a longer chain of reasoning gives a worse answer. A gate provides the check and the order, so work can run longer without losing quality. There is no sample data for “a gate lengthened autonomous work”; below are the facts the idea rests on.
What a task horizon is. METR measures the length of a task an agent completes with a given probability of success, in the time a human needs for it. This is not the agent’s run time. For Claude Opus 4.6 the horizon at 50% success is about 12 hours (a confidence interval from 5 to 61 hours), and at 80% about 70 minutes. For GPT-5.4 it is 5.7 hours and 54 minutes. Above 16 hours METR considers measurements unreliable. How autonomy metrics work and where a person sits in them: in the article “Escalation to a human in AI agents”.
The price of reliability. Toby Ord showed that with a constant chance of failing per minute of work, the horizons are linked by a formula. The consequence: the horizon at 80% success is about a third of the one at 50%, at 90% about a seventh, at 99% about a seventieth. Each extra “nine” of reliability costs task length.
A worked example: at 95% success per step, 36% chance remains after 20 steps, and at 99% per step 82%.
Where the gate is here. A gate on a step raises the step’s reliability. If a step fails with a 5% chance and the gate catches 4 errors out of 5 and sends the agent back to fix them, the step ends up breaking in 1% of cases. The arithmetic assumes independent steps: Ord himself notes that for Claude 3.7 Sonnet the measured ratio of horizons is 0.25 while the theory gives 0.32. The chart shows a direction: 82% is a calculation with no measured result behind it.
Two Anthropic mechanisms for long runs. The first: each agent session starts with no memory of earlier ones, and compacting the dialogue is not enough. So at the start the agent wrote a list of more than 200 features, all marked “failing”. The agent may change only the pass mark, and editing the tests themselves is forbidden. Such a list is gate state that lives in a file outside the dialogue: a new session sees how much remains and cannot decide that everything is done.
The second mechanism concerns “context anxiety”. Models start wrapping work up when they think the context window is about to end. A gate with criteria from the list makes the decision to finish depend on green marks, and the agent’s feeling takes no part in it. Hence the conclusion: a bounded context should be sized to fit into the physical context window.
A hook as a continuation mechanism. In Claude Code a task-completion hook does not let a task close until the checks pass: the refusal message returns to the agent, and it continues. A stop hook works the same way for finishing the whole turn.
Where to put it: at a bounded-context border
A gate belongs at a bounded-context border for four reasons. Each has support in sources.
1. A check inside a frame is finite. No check can verify any program against any rule, so the check goes where a frame limits the question. Why this is so and how an aggregate border becomes a checkpoint is in the article “Where to check an AI agent’s work”. For a gate it follows: a gate without a border will answer “not sure” too often.
2. A small change succeeds more often. The more an agent changes at once, the less often the task is solved. A context border limits the size of a change naturally.
The numbers on the chart come from two works: SWE-bench Live and the Kozuchi agent on SWE-bench Verified (arXiv 2608.15579). The benchmarks and agents differ, so the direction is what matters: the bigger the change, the less often it succeeds. At team level DORA shows the same: the benefit of AI depends on working in small batches.
On SWE-bench Live a change in one file under five lines is solved in almost half the cases (48%), three or more files or over a hundred lines in under 10%, and seven or more files never (arXiv 2505.23419). The Kozuchi agent on SWE-bench Verified solves 81.7% of tasks with a change of 1–4 lines and 41.7% with a change over 100 lines (arXiv 2608.15579). These are different benchmarks and agents, so the direction is what matters. DORA adds a team-level conclusion: the benefit of AI depends on working in small batches.
3. The context window is limited. Context is a finite resource with diminishing returns. Chroma tested 18 models and showed that reliability falls as input grows. In a 2024 talk Evans noted that a model’s answers are steadier when a request is broken into smaller chunks (as reported by InfoQ). A small bounded context gives the agent a short window, and the gate has less chance of checking something the agent no longer remembers.
Each context has its own agent, its own small window, its own set of MCP functions and a gate on the border. Events travel between contexts.
4. On the border it is clear who is to blame. In Bertrand Meyer’s design by contract a precondition violation is the caller’s bug and a postcondition violation is the supplier’s bug. A gate on the border shows at once whose bug it is: a bad command came in or a bad event went out. Evans advises putting a protective layer on the border that translates foreign concepts into your own. The gate stands on that layer.
What a bounded context and an aggregate are, and how the number of contexts relates to the number of agents, is in the articles “How many AI agents do you need” and “Specs by aggregate”.
MCP: permissions, function set and the place of a gate
MCP is a protocol through which an agent calls functions of external systems. It matters twice for gates: an MCP server can hard-limit what is available to the agent, and the function set decides how much context the agent spends on descriptions.
What an MCP server can forbid and what it only suggests
| Mechanism | Strength | What the specification says |
|---|---|---|
| Permissions and scopes | a ban | when permissions are insufficient the server answers 403 and names the needed scope; in version 2026-07-28 the function list may depend on the caller’s permissions |
| Result by schema | a verdict | the server must return a result matching the declared schema, so a verdict “accepted / not accepted” is machine-readable |
| A question to a person | a question | the server may ask a person; the answer is accept, decline or cancel |
| Function labels | a hint | “read-only”, “destructive” are hints, and the client need not trust them |
| Root folders | a hint | the server “should” respect the borders, but nothing enforces it |
Confirmations from the specification: a result by schema, a function list by permissions and function labels. More on the scopes of MCP servers in Claude Code is in the article “MCP scopes”.
A narrow function set: two effects from one mechanism
Descriptions of 58 functions took about 55 thousand tokens. With search over functions the needed ones load on demand: about 8.7 thousand.
The first effect is context. Anthropic showed that 58 functions took about 55 thousand tokens, and about 8.7 thousand with search over functions, while the accuracy of picking a function rose for Opus 4 from 49% to 74% and for Opus 4.5 from 79.5% to 88.1%. In another example, running code instead of direct calls cut consumption from 150,000 to 2,000 tokens. Anthropic’s own conclusion: more functions do not mean a better result.
The second effect is permissions. The same settings limit permissions. In Claude Code a subagent has a list of allowed functions, a list of forbidden ones and its own set of MCP servers that the main dialogue does not have. One narrow set per bounded context means both a short window and less opportunity to break something. This is my conclusion: the figures above were measured for tokens, and none exist for security.
Why the gate stands behind MCP and why an agent has no incentive to stop
The author’s hypothesis, research in preparation. Agents are measured and, as I assume, optimised for autonomous run time: the main progress metric is the length of a task an agent does without a person (METR). MCP has a request to a person: the server may ask, and the answer is “accept”, “decline” or “cancel”. For such a metric every question to a person is a loss of autonomy, so an agent has no incentive to stop and ask. On top of that MCP is a narrow neck: calls to functions and their answers pass through it, but the meaning of the whole work does not. The conclusion: a gate cannot rest on the agent’s good will, it stands outside the agent, behind a separator. How agents are actually trained and how the metrics are counted I have not verified, and a separate article is devoted to it.
A kindred border runs between the agent’s commands (control plane) and the data it reads (data plane): data must not become commands. The author’s talk at Podlodka AI Crew is about this, “AI agent in production: architecture, protection, economics” (slides in Russian), and so is the article “Data plane and control plane of an agent”.
Where the gate should stand: outside the agent
A rule in text the agent can bypass. A gate in a client hook or in server permissions it cannot.
| Where the gate lives | Reliability | Why |
|---|---|---|
| A phrase in the instructions | advice | the agent may skip it |
| A client hook before a call | a ban | blocks a call to an MCP function by a pattern of server and function name |
| A stop hook | a ban | does not let the turn end until the check passes |
| A hook after a call | a signal | the function has already run |
| Server permissions | a ban | the check stands in the system the agent calls |
According to the Claude Code documentation: a hook before a call blocks the call, a stop hook does not let Claude finish the turn, and a task-completion hook does not let a task close. A hook after a call blocks nothing: the function has already run. A hint in text stays advice, as the author of an analysis of stop hooks notes. OWASP advises checking permissions where the action is executed.
A weak spot: a check the agent calls itself. If the check is an MCP function, the agent may call it or not, and then there is no verdict. The ready-made agent-gate server works this way: the agent sends the evidence itself, and the server returns a verdict and appends it to a log in which the entries are linked by hashes. That is self-checking with the blind spots from the self-grading section. The client is also required to treat function labels as untrusted. It is safer when a hook or an orchestrator calls the verdict server: the agent cannot bypass the verdict.
Which ready-made programs I did not find. MCP gateways cover permissions, secrets and leaks: agentgateway (a Linux Foundation project), and the Microsoft, Docker and Lasso gateways. I found no gate for “the work was done correctly” among them. Microsoft’s quality-gates set for spec-driven development turned out to be a checklist for the agent itself, with no server in it.
Limits of a gate: how it is bypassed and why it breaks on its own
Four paths around a gate: editing a test, special-casing a test, hidden intent and a reviewer who got used to it.
The agent fits the result to the check. METR recorded that o3 cheated the evaluation in 0.7% of runs, and on one task 21 times out of 21. In the Claude 3.7 Sonnet system card Anthropic acknowledges that the model sometimes returns the test’s expected values instead of a general solution or edits the tests themselves. ImpossibleBench made tests contradict the task and counted any pass as cheating: GPT-5 cheated in 54% of cases. Read-only tests remove test editing but not special-casing.
Monitoring reasoning is better, but do not pressure it. An action monitor catches 60% of hacks, a reasoning monitor 95%. But if the agent is trained with pressure on its reasoning, the monitor’s recall falls to near zero, because the agent learns to hide its intent.
A gate that refuses forever. In Claude Code, after eight stop-hook refusals in a row the program ends the turn itself. The limit can be changed with an environment variable, but the principle stands: a gate needs an attempt limit and a handover to a person. At Stripe it is at most two CI runs, and Microsoft devsquad allows two correction attempts.
A gate that is too strict. According to InfoQ’s report of Spotify’s QCon London talk, published on 18 March 2026, the judge was found too rigid, blocked valid changes and was later removed, leaving checks in the prompts. This is a retelling, and I found no such statement in Spotify’s own posts. Cursor names the “integrator” role as a bottleneck.
The author’s heuristic: many relevant gates. I noticed that several gates, one per risk (types, tests, a linter, a check of meaning), work better than one big one. This is an observation; no source compares “one gate and many”. It fits what I found: Stripe alternates linters and CI, Sonar requires six conditions at once, Thoughtworks names compilers, linters and tests together. It does not cancel the limits above: each gate has a price and an attempt limit, and a gate that is too strict does harm, like Spotify’s judge. So “relevant” means tied to a risk that would otherwise reach the user.
The reviewer gets used to it. Over seven months, among 400 repeat reviewers the approval rate rose from 30.1% to 36.8%, the review queue slowed by 3.5 times and inline comments fell by 22% (arXiv 2606.22721, 11,429 reviews). According to Faros AI, among more than 10,000 developers using AI, PR size grew by 154% and review time by 91% (Faros AI, 23 July 2025).
Sensors do not see meaning. Böckeler notes that sensors catch misdiagnosis, needless complexity and misread tasks unreliably. A gate answers for what is written as a rule, and the rest stays with a person.
| Danger | Defence |
|---|---|
| The agent edits or bypasses tests | tests and the gate itself are read-only; only the check program sets the “passed” mark |
| Special-casing a test | a second layer: a reviewing agent by meaning and random checks |
| The agent hides its intent | watch the reasoning but do not train the agent against it |
| The gate is red forever | an attempt limit, then a handover to a person |
| The gate blocks the correct | track what share of refusals is wrong and loosen the rule |
| The reviewer got used to it | show the person only “not sure” cases and risk |
How to start: five steps and ready prompts for the agent
Start with one context and one task. Each step below closes one item of the limits section. Prompts can be given to the agent as they are, with your project filled in.
1. Write “done” as a file
Create an acceptance.json file with a list of checkable “done” criteria for the task [description]. Each criterion: id, text, check command and a passes field set to false. Rules: only the check script changes passes, and criteria are not deleted or edited without my confirmation.
2. Set a stop gate
Configure a Claude Code stop hook in .claude/settings.json: before a turn ends, run a check script that executes the commands from acceptance.json and updates passes. If any criterion is red, block the finish and return the error text to the agent. Check the stop_hook_active flag so the hook does not loop. After three red attempts in a row, end the turn and tell me exactly what does not pass.
3. Close the bypasses
Forbid the agent to write to the tests directory, to acceptance.json and to .claude. Add a check that the number of tests did not decrease and no test is marked as skipped.
4. Add a reviewer by meaning
Create a separate reviewing subagent with read-only access. It compares the final change with the original task and scores each criterion from [list] from 0 to 5. Below 4 on any criterion means the change is not accepted. Verdict: accepted, not accepted with a reason, or not sure.
5. Narrow the set of MCP functions
List the MCP functions the agent used in this context over the last month. Keep only those in this context’s subagent settings and disable the rest. Show how many tokens were freed.
After that a loop works: each error the gate missed becomes a new check. This is the general principle from the article “Harness engineering in practice”, and a gate is its special case. And keep a log of verdicts: how many steps the agent passed without a person before the gate and after it. This is the very autonomy metric that research lacks.