AgentSessionManager.StreamSession (AgentSessionManager v0.8.0)

Copy Markdown View Source

One-shot streaming session lifecycle.

Starts a store and adapter under supervision, runs SessionManager.run_once in a monitored task, and exposes the event stream as a lazy Stream.resource.

Usage

{:ok, stream, close_fun, meta} =
  StreamSession.start(
    adapter: {ClaudeAdapter, model: Models.default_model(:claude)},
    input: %{messages: [%{role: "user", content: "Hello"}]}
  )

stream
|> Stream.each(&IO.inspect/1)
|> Stream.run()

close_fun.()

With existing store and adapter

{:ok, stream, close_fun, meta} =
  StreamSession.start(
    store: existing_store_pid,
    adapter: existing_adapter_pid,
    input: %{messages: [%{role: "user", content: "Hello"}]}
  )

Options

  • :adapter — Required. {AdapterModule, opts} tuple or a pid of a running adapter.
  • :input — Required. Input map for SessionManager.run_once/4.
  • :store — Optional. Pid of an existing SessionStore. Defaults to starting an InMemorySessionStore.
  • :agent_id — Optional. Agent identifier for the session.
  • :run_opts — Optional. Additional keyword opts forwarded to SessionManager.run_once/4.
  • :idle_timeout — Optional. Stream idle timeout in ms. Default: 120_000.
  • :shutdown_timeout — Optional. Task shutdown grace period in ms. Default: 5_000.

Summary

Types

close_fun()

@type close_fun() :: (-> :ok)

meta()

@type meta() :: map()

stream_event()

@type stream_event() :: map()

Functions

start(opts)

@spec start(keyword()) ::
  {:ok, Enumerable.t(), close_fun(), meta()} | {:error, term()}