The runtime interface
A runtime is how an agent’s “brain” is loaded and driven for one iteration.
Where providers and tooling are I/O, a runtime is the program the agent runs:
it is handed the agent’s brain (a wasm component, a rhai script, or a js script)
and asked to execute it against the AgentContext.
Named runtimes live in the global [runtime.<name>] config map. Each agent
wiring pins itself to one by name.
The abstraction
A runtime exposes, through the WIT runtime interface (exported by the guest
component and called by the host):
kind()— which brain implementation this is (wasm,rhai, orjs).run(script)— run one iteration. Returns the terminal message if the brain chose to exit, otherwise nothing.
The host’s Runtime::run(&AgentContext) drives this off the tokio worker on a
spawn_blocking thread (the wasm engine and the rhai / js interpreter
components built on it are synchronous). The script argument is the agent’s
brain. For a wasm brain the program is baked into the component and the script
is unused, while for Rhai it is the Rhai source text and for JS it is the
JavaScript source text.
How a run happens
build(kind) dispatches to wasm, rhai, or js. Each runtime loads its
engine, and pushes a blocking task that:
- builds a
Storewhose data is the runtimeHost(the agent context, a resource table, and a WASI context), - wires the imports — the WASI wasip2 imports plus the
provider,tooling, andhostinterfaces — into aLinker, - instantiates the component,
- calls the exported
runtime.run(script)and - surfaces the terminal message as
Exited(message)orCompletedif the brain ran to a finish.
The agent context
Every runtime call receives an AgentContext: the agent name, the brain
script path, the named providers and tooling registries, the shared
MessageBus, the agent’s own StreamRegistry (chat streams), the timer
CancelRegistry, the resource-subscription CancelRegistry, and the dedicated
tokio rt used to bridge synchronous host calls to the async provider/tooling.
Provider and tooling registries, and the message bus, are shared across all
agents in one process — the StreamRegistry, timer/resource registries, and
bridge runtime are per-agent.