module

Anthropic::Sessions

Helpers for Managed Agents session event streams.

Class methods

accumulate_managed_agents_event(accumulated : JSON::Any | Nil, event : JSON::Any) : JSON::Any | Nil

Fold Managed Agents session/preview streaming events into a buffered agent.message snapshot (returned as a JSON::Any object).

Mirrors the TypeScript/Python accumulate_managed_agents_event helper. Pass the previously accumulated snapshot (or nil) plus the latest event, and receive the updated snapshot (or nil for non-agent.message events that don't affect the accumulator).

  • event_start with event.type == "agent.message" opens a fresh snapshot {id, type: "agent.message", content: [], processed_at: ""}.
  • event_delta folds delta.content into content[delta.index ?? 0].
  • agent.message (buffered final) replaces the snapshot.
  • All other event types are no-ops returning accumulated unchanged.

Returns nil if a delta arrives before its event_start (the caller should drop stray deltas), per the official manual-deltas example.

Source

Nested types