Technology · Discipline

Code generation and metaprogramming

I generate code where repetition is the risk: a generator that emits a whole function and wires it into the estate transactionally, and YAML tool schemas compiled into dispatch at build time.

Rust · Handlebars templatesYAML compiled to dispatchOpenAPI compiled to a catalog
One call · a crate, and the estate edited around it gatewaycontrol planecompletion service
createdeleteupdate
1 callto create_function
  • 8 + 6files in each generated crate: framework the author leaves alone, and a sandboxed developer zone
  • 7 of 14function crates in the estate carry the generator's fingerprints
  • 83operations compiled from a vendor's OpenAPI specification into an internal catalog
  • 15points in the integration check the first generator passed while its code did not compile

A generator that wires a function into the estate

In FAFO Core and Function Forge, every new capability used to mean a person wiring a crate into the gateway, the control plane and the result path by hand, and a half-wired function shows up later as a hang. I decided agents should generate fully wired functions themselves, inside a sandbox, active only after a human rebuild.

Function Forge is a Rust generator built on Handlebars templates and exposed as an MCP (Model Context Protocol) tool. One create_function call emits the crate and, in the same rollback-protected transaction, edits the rest of the estate: the gateway's module, function and metadata definitions, the control plane's composition root and the completion service's dispatch. Those edits go into hand-written Rust at marked landmarks, and delete_function reverses each one by landmark and removes the crate.

After create_functionGateway modules and metadataControl plane composition rootCompletion service dispatchand a new crate, linked in
After delete_functionGateway modules and metadataControl plane composition rootCompletion service dispatchthe crate removed
Grey is hand-written code; colour is generated. Positions are illustrative.

The generator creates and deletes and never updates, because an update would overwrite the developer zone. The full account is Tools that build tools, under governance.

The sandbox and the rebuild

The first generator passed its own integration check and produced code that did not compile. I had it redesigned around the sandbox and inverted file ownership, and the first design was discarded. The developer zone now sees a capability-bounded context object, which keeps AI-authored logic inside the governed write path.

The governed write path
The developer zone · AI-authored logic
a capability-bounded context object, the only way out
raw connections
direct database writes
vector search
An authoring guide is compiled into the tool.

Generated crates register themselves at link time, so a function is either compiled in fully wired or the build fails. Activation is a rebuild plus a human restart. Hot-loading would be faster, and the restart is the governance step.

Tool schemas compiled into dispatch

The gateway compiles YAML tool definitions into dispatch code and JSON-Schema tool inputs at build time, which is how a new function appears in the tool list with no hand-written registration.

A vendor specification, compiled and kept private

FAFOHive needed an X integration, and the vendor's OpenAPI specification describes far more than an agent should see. I had a generator compile the specification into a typed internal catalog of operations, each with method, path, safety class, unit cost, fields and pagination, with credential fields injected on the server.

Generated · internal
Designed · what agents see

About fifteen workflow tools with costs and guards, built on top.

The generated breadth stays private.