Session context created via createContext()
Optionalopts: { traceWriter?: TraceWriter }Agent handle with session, store, and event channel
main(function*() {
const ctx = yield* call(() => createContext({
modelPath, nCtx: 16384,
nSeqMax: 4, typeK: 'q4_0', typeV: 'q4_0',
}));
const { session, events } = yield* initAgents(ctx);
// Ctx, Store, Events are now set — generate(), diverge(),
// useAgentPool() will find them automatically.
// Cleanup runs on scope exit.
});
Bootstrap the agent infrastructure and register structured cleanup
Creates BranchStore, Session, and an event channel, then sets all three Effection contexts (Ctx, Store, Events) in the caller's scope. Cleanup runs on scope exit (Ctrl-C, error, normal completion) via
ensure().Context values are set in the caller's scope — visible to all subsequent operations. This is why
initAgentsusesensure()rather thanresource(): a resource creates a child scope whereCtx.set()would be invisible to sibling operations.The caller creates the SessionContext (model path, nCtx, KV types are harness-specific decisions) and passes it in.