Real-time event streaming for agent sessions.
Provides a pub/sub mechanism for observing agent activity. Subscribers
receive events as they happen -- tool calls, text output, state changes,
errors. Used by SessionStreamServer for HTTP/SSE delivery.
Usage
# Subscribe to events from an agent session
SessionStreamer.subscribe(session_id)
# Events arrive as messages:
receive do
{:session_event, ^session_id, event} -> handle(event)
end
# Emit an event (called by agent infrastructure)
SessionStreamer.emit(session_id, {:text_delta, "Hello"})
# Unsubscribe
SessionStreamer.unsubscribe(session_id)Event Types
Events mirror Raxol.Agent.Stream types:
{:text_delta, text}-- streaming text chunk{:tool_use, %{name, arguments, id}}-- tool invocation{:tool_result, %{name, result}}-- tool result{:state_change, %{from, to}}-- agent status transition{:turn_complete, info}-- end of one reasoning turn{:done, info}-- session completed{:error, reason}-- error occurred
Summary
Functions
Returns a specification to start this module under a supervisor.
Emit an event for a session (broadcast to all subscribers).
Get recent event history for a session.
List sessions with active subscribers.
Start the SessionStreamer (typically in your supervision tree).
Subscribe the calling process to events from a session.
Unsubscribe the calling process from a session.
Types
@type session_id() :: term()
@type t() :: %Raxol.Agent.SessionStreamer{ history: %{required(session_id()) => :queue.queue()}, max_history: pos_integer(), subscriptions: %{required(session_id()) => MapSet.t(pid())} }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec emit(session_id(), event(), GenServer.server()) :: :ok
Emit an event for a session (broadcast to all subscribers).
@spec history(session_id(), GenServer.server()) :: [event()]
Get recent event history for a session.
@spec list_sessions(GenServer.server()) :: [session_id()]
List sessions with active subscribers.
@spec start_link(keyword()) :: GenServer.on_start()
Start the SessionStreamer (typically in your supervision tree).
@spec subscribe(session_id(), GenServer.server()) :: :ok
Subscribe the calling process to events from a session.
@spec unsubscribe(session_id(), GenServer.server()) :: :ok
Unsubscribe the calling process from a session.