Vibe.Agent.Streaming (vibe v0.2.2)

Copy Markdown View Source

Dispatches Jido streaming lifecycle signals to per-agent callbacks.

The server keeps transient callback registrations outside the agent process so CLI, TUI, and session callers can attach stream handlers for one request. ReAct runtime deltas are ordered by runtime sequence before dispatch because signal arrival order is not a reliable transcript order.

Summary

Functions

Returns a specification to start this module under a supervisor.

Dispatches a derived ai.llm.delta signal unless runtime deltas own the call.

Dispatches a ReAct runtime delta using its runtime sequence when present.

Sends a terminal tool-result lifecycle event to registered callbacks.

Sends a streamed tool-parameter update to registered callbacks.

Sends a tool-start lifecycle event to registered callbacks.

Flushes and clears buffered runtime deltas for a completed LLM call.

Registers stream callbacks for a running Jido agent process.

Starts the streaming callback registry.

Removes callbacks and runtime ordering state for an agent process.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dispatch(agent_id, chunk)

@spec dispatch(String.t(), ReqLLM.StreamChunk.t()) :: :ok

Dispatches a derived ai.llm.delta signal unless runtime deltas own the call.

Derived deltas do not always carry ordering metadata, so they are suppressed after a ReAct runtime delta is observed for the same {agent_id, call_id}.

dispatch_runtime_delta(agent_id, call_id, chunk)

@spec dispatch_runtime_delta(String.t(), String.t() | nil, ReqLLM.StreamChunk.t()) ::
  :ok

Dispatches a ReAct runtime delta using its runtime sequence when present.

Out-of-order runtime arrivals are buffered per {agent_id, call_id} until the missing sequence arrives or the call finishes.

dispatch_tool_finished(agent_id, event)

@spec dispatch_tool_finished(String.t(), Vibe.Tool.Event.t()) :: :ok

Sends a terminal tool-result lifecycle event to registered callbacks.

dispatch_tool_preparing(agent_id, event)

@spec dispatch_tool_preparing(String.t(), Vibe.Tool.Event.t()) :: :ok

Sends a streamed tool-parameter update to registered callbacks.

dispatch_tool_started(agent_id, event)

@spec dispatch_tool_started(String.t(), Vibe.Tool.Event.t()) :: :ok

Sends a tool-start lifecycle event to registered callbacks.

finish_runtime_call(agent_id, call_id)

@spec finish_runtime_call(String.t(), String.t() | nil) :: :ok

Flushes and clears buffered runtime deltas for a completed LLM call.

register(agent_pid, opts)

@spec register(
  pid(),
  keyword()
) :: :ok

Registers stream callbacks for a running Jido agent process.

Supported callbacks are :on_result, :on_thinking, :on_tool_preparing, :on_tool_started, and :on_tool_finished. Empty callback registrations are ignored so callers can pass optional streaming options directly.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the streaming callback registry.

unregister(agent_pid)

@spec unregister(pid()) :: :ok

Removes callbacks and runtime ordering state for an agent process.