Skip to content
· 5 Min. Lesezeit

Designing an agent policy engine

Most agent policy engine designs I read are settings screens with a database behind them. A screen collects a number, the database stores it, and something in the middle compares the number to the number in the request. That is not a policy engine. It is a threshold with a user interface, and it will work until the first time somebody has to explain a decision.

What the engine actually has to do


  • Compile a document a person wrote into something a machine can evaluate, without changing what they meant.
  • Evaluate one proposed action against that document, atomically with the record of the evaluation.
  • Answer the question why, for every decision, months later, in language a non engineer can check.
  • Refuse cleanly when it does not understand, including when the document is malformed, the clock is wrong, or a dependency is down.
  • Let the document change over time without rewriting the past.

Only the third of those is where the design fights happen. Everything else is engineering. The ability to answer why is what forces the shape of everything else.

The five decisions


One: the language has no escape hatch. A rule cannot call a remote service, cannot read the clock unless the clock is passed in as part of the request, and cannot contain an arbitrary expression evaluated at decision time. The moment you allow one, determinism is gone, and the record can no longer be recomputed. My policy language is a small declarative structure on purpose. It is less powerful than a scripting language and it is the reason the why is always answerable.


Two: unknown means denied. If the request does not parse, if the mandate version is missing, if the amount is not a number, if the merchant is not identified, the answer is deny. Fail closed is unfashionable because it produces support tickets, and I would take the tickets. An engine that fails open is an engine whose worst day is its quietest.


Three: policies are immutable once used. A version that has been evaluated against a live decision is never edited. Changing a policy creates a new version with an effective date, and the record names the version it was judged against. Retroactive change is how an audit trail becomes fiction, and it is always done with a good reason by someone who has not thought about the reason yet.


Four: simulate before you ship a rule. Every candidate version runs against a sample of past decisions in dry run, and the output is a diff: which past requests would now allow, which would now deny, which would now escalate. This is the cheapest safety tool I know of and almost nobody builds it, because the happy path of a policy engine is a number that goes down and nobody celebrates a number that goes down.


Five: the engine is not allowed to learn. Not from behaviour, not from outcomes, not from the shape of the requests. A policy that adapts is a policy nobody signed. Some products in this category infer what you will allow and ask afterwards, which is a reasonable product, and it is a different one from the one described in the paragraph above. Mine asks first.

Where the user's sentence goes


The user should write the boundary in their own words and the system should compile it. This is the part of the design I feel most strongly about, because it decides whether the record will mean anything. If the boundary is expressed in the system's vocabulary, the user is approving a translation they cannot check. If it is expressed in theirs, the compiled document and the sentence can sit next to each other in the record, and a reader months later can compare the two.


The test is recognition, not comprehension. The user does not need to understand the document. They need to recognise it as the thing they meant, which is a much lower bar and the only one that scales to people who will never read a policy language.


What I would not build. A user interface first. The temptation is to collect the settings, because settings are easy to demo and easy to sell, and the engine is downstream of them. The result is an engine that can only express what the interface could think of, and every new capability becomes an interface change rather than a rule change. I built the decision function and the record first and treated the interface as a compiler front end for a language that already existed. It is less comfortable to demo and much cheaper to extend.


A marketplace of rules, or anything that learns. Both appeared on my list of tempting ideas and both are out. Rules that arrive from outside the trust boundary are code that runs inside a decision about money, and rules that adapt are rules nobody signed. If the boundary is wrong, the user has to be able to read it, argue with it, and replace it, and that only works if it is short, local and stable.


The error messages. This is the unglamorous part that I would defend hardest in a design review. When a policy document fails to compile, the message should say which line, which field, and what was expected, in the user's vocabulary rather than the parser's. A boundary the user cannot fix themselves is a boundary that will be abandoned, and an abandoned boundary is worse than a strict one because it stays in place with nobody reading it.

What it costs to run


Less than people expect. A decision is a handful of comparisons against a compiled structure, and the expensive part is not the evaluation, it is the record write, because the chain has to be serialised. That is also the constraint that makes concurrency correct: one writer for the chain means the budget check and the decision row are in the same transaction, and the race I found with an external auditor stops being possible rather than being handled.


I am building this at Noesia. What the document contains is in what should an AI agent be allowed to do, the property that makes the evaluation replayable is in deterministic authorization for AI agents, and the why that the engine is built around is in what an agent authorization record should contain. If you have built one of these and made different calls, particularly on learning and on dry run, I would like to read the argument. Why I care about the boring version is on boring systems.

Building Know Computer, a personal context layer for the AI era. Reply via [email protected].

Mehr

Notizen