runtime option) and is automatically propagated to runtime-aware tools (createRuntimeTool).
Instantiation
Main methods
Static helpers
RuntimeStore.current()– return the runtime currently bound to the async context.RuntimeStore.requireCurrent()– throw if no active runtime is available.RuntimeStore.mergeExperimentalContext(base, runtime)– merge a runtime intoexperimental_context(used by agents).RuntimeStore.resolveFromExperimentalContext(context)– retrieve the runtime from anexperimental_contextobject.
createRuntime and withRuntime
createRuntime(init?)– convenience wrapper aroundnew RuntimeStore(init).withRuntime(runtime, callback)– create a snapshot, execute the callback, and automatically dispose resources even when it throws.
Resource management
runtime.load(name, source) relies on resources registered via registerRuntimeResource(name, { loader, dispose }). The loader receives the source and current runtime; the disposer runs when the request ends or dispose is called manually.
Agents & tools integration
- Pass
runtimetoagent.generate/agent.streamso runtime tools (createRuntimeTool) can access shared data viaruntime.require(key). - Cleanup handlers (
onCleanup) guarantee proper resource disposal even with streaming or cancellations. - Runtimes chain nicely:
snapshot()creates a parented clone, andRuntimeStore.current()lets tools retrieve it without explicit parameters.