babel-plugin-agent-compiler is an internal Babel plugin used by the Guild runtime to translate procedural TypeScript agent code into state machines that can be paused, serialized, and resumed.
This plugin is what enables AutomaticallyManagedStateAgent — agents written as straightforward async functions can be suspended when waiting for user input or long-running operations, and resumed later even after a runtime restart.
How it works
The compiler transformsasync functions into state machine objects with three methods:
step— Runs the state machine until it reaches anawaitexpression, then returns the pendingPromiseget— Serializes the entire state machine state as a JavaScript object for storageset— Restores a previously serialized state
get to persist state when an agent is suspended (for example, while waiting for user input), and set to restore it when the agent resumes.
Limitations
The compiler handles most straightforward TypeScript code, but has constraints related to serializing opaque values across suspension points.Promise methods
StaticPromise methods cannot be used across await points:
Promise.allPromise.anyPromise.race
SelfManagedStateAgent instead.
Dynamic function references
Conditionally assigned functions may not survive serialization:Imports
The compiler does not traverse imported functions. Only code within the agent file itself is compiled.Direct Promise usage
If your code directly creates or manipulatesPromise objects, the compiler cannot reliably serialize the state at those points. Use await expressions instead.
This package is used internally by the Guild runtime. You do not need to install or configure it directly when building agents.