Implementation:A5c ai Babysitter session event persistence
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Kubernetes, Event_Sourcing, Session_Management |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for persisting agent session events from SSE streams with budget enforcement and transcript accumulation.
Description
The persistSessionEvent method on the agent dispatch controller processes SSE events from agent pod execution. It:
- Mutates the AgentDispatchRun in place (status: Running, Completed, Failed)
- Mutates the AgentDispatchAttempt in place (status tracking)
- Accumulates messages in the AgentSessionTranscript with cost tracking
- Checks budget after each event — exceeds → run Failed with budget_exceeded reason
- Terminal events emit run-complete notifications
Usage
- Agent dispatch Step 7: Persist session events as they arrive from the agent pod callback.
Code Reference
Source Location
- Repository: Babysitter
- File: packages/kradle/core/src/agent-dispatch-controller.js:L174-294
Signature
controller.persistSessionEvent(event, run, attempt, options): {
run, attempt, transcript, notification
};
// event: { type, content, role, usage, toolUse, toolResult }
// options: { namespace, organizationRef, transcript }
Import
import { createAgentDispatchController } from "@a5c-ai/kradle";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| event | object | Yes | SSE event (type, content, role, usage, toolUse, toolResult) |
| run | AgentDispatchRun | Yes | Mutated in place |
| attempt | AgentDispatchAttempt | Yes | Mutated in place |
| options.namespace | string | Yes | K8s namespace |
| options.transcript | AgentSessionTranscript | Yes | Message accumulation |
Outputs
| Name | Type | Description |
|---|---|---|
| run | AgentDispatchRun | Updated status |
| attempt | AgentDispatchAttempt | Updated status |
| transcript | AgentSessionTranscript | Accumulated messages and cost |
| notification | object | Run-complete notification (terminal events only) |
Usage Examples
Persist SSE Events
import { createAgentDispatchController } from "@a5c-ai/kradle";
const controller = createAgentDispatchController();
// Process events from agent pod SSE stream
for await (const event of sseStream) {
const result = controller.persistSessionEvent(
event,
run,
attempt,
{ namespace: "kradle", organizationRef: "my-org", transcript }
);
if (result.notification) {
console.log("Run completed:", run.status.phase);
break;
}
if (run.status.phase === "Failed") {
console.error("Run failed:", run.status.reason);
break;
}
}
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment