Around all of it

Compilers for Agent Systems

A model-generated plan is a program in an untrusted language. Parse it, type it, validate it and check its permissions before any of it executes.

A Plan Is a Program

A model-generated plan is source code in an untrusted language written by an unreliable author. That single reframing hands you a whole compiler frontend of techniques — a grammar, a parser, name resolution, a type checker and an authorization pass — and tells you the order to run them in.

Q · A model just handed my system a plan to execute. What should happen to it before anything runs?
Agent DSLs and the Plan AST

Give the agent a small language with a grammar, and its plans become trees you can print, diff, refuse, rewrite and replay. `SEARCH(...) |> FILTER(...) |> SUMMARIZE()` as an AST before any tool runs is worth more than the same three calls made one at a time, and the reasons are the ordinary reasons an IR exists.

Q · Why should an agent produce a plan in a small language instead of just calling tools one at a time?
Typed Tool Calls
▶ lab

A tool call is a function call whose arguments came from an untrusted source, so the boundary needs a type checker. JSON Schema is that type system, constrained decoding is the technique that makes malformed calls unsamplable rather than merely detectable, and neither of them says anything about whether the call should happen.

Q · How do I turn a model's tool call into a typed function call I can actually dispatch?
Parse, Validate, Authorize, Execute

Four gates, each rejecting a class of problem the others structurally cannot, in an order that is not arbitrary. The reason the ordering matters is the same reason `[[phase-ordering]]` matters in a compiler: a later phase depends on facts an earlier one established, and running them out of order either weakens the check or leaks information.

Q · In what order should I check a model-generated plan, and what does each check actually establish?
Recovering Structure From Model Output

The practical lesson: how to get a reliable data structure out of text a model wrote. A strict parser with real error recovery beats a pile of regular expressions for the same reasons it does in a compiler, repair-and-retry is a legitimate strategy with a cost worth naming, and no parser will ever tell you whether the output meant what the user wanted.

Q · The model wrapped its JSON in prose and left a trailing comma. Do I regex it, repair it, or reject it?