Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A5c ai Babysitter session event persistence

From Leeroopedia
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:

  1. Mutates the AgentDispatchRun in place (status: Running, Completed, Failed)
  2. Mutates the AgentDispatchAttempt in place (status tracking)
  3. Accumulates messages in the AgentSessionTranscript with cost tracking
  4. Checks budget after each event — exceeds → run Failed with budget_exceeded reason
  5. 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