ReqManagedAgents.Session (ReqManagedAgents v0.1.0)

Copy Markdown View Source

The one agent loop, provider- and transport-agnostic.

A Session drives any ReqManagedAgents.Provider to completion: invoke a turn → normalize → run the return-of-control tools locally via the :handler → resume → repeat until a terminal. The provider's mode/0 (:streaming push or :request_response pull) only changes how a turn's events are acquired; the loop, the result shape, and the raw-event passthrough are identical across providers.

Pick a provider — ReqManagedAgents.Providers.ClaudeManagedAgents (streaming) or ReqManagedAgents.Providers.BedrockAgentCore (request/response) — and:

# synchronous run-to-completion
{:ok, %ReqManagedAgents.SessionResult{terminal: t, stop_reason: r, events: raw}} =
  ReqManagedAgents.Session.run(provider, handler: MyTools, prompt: "Hi", ...)

# live, long-lived (stays alive after a terminal; `:notify` gets {:managed_agents_session, %ReqManagedAgents.SessionResult{}})
{:ok, pid} = ReqManagedAgents.Session.start_link(provider, handler: MyTools, notify: self(), ...)
ReqManagedAgents.Session.message(pid, "follow-up")

Required opts: :handler (a ReqManagedAgents.Handler module or a 3-arity fn). Optional: :context, :prompt, :timeout, :max_turns, :notify, :name, :telemetry_metadata. Provider-specific opts (e.g. :agent_id/:environment_id, :harness_arn/:runtime_session_id, :session_id to resume) are forwarded to the provider's open/2.

Summary

Functions

Return a child_spec for a live session.

Send a follow-up user message into a running live session.

Start a long-lived session. Unlike run/2, it stays alive after a terminal for follow-ups.

Functions

child_spec(init_arg)

Return a child_spec for a live session.

message(pid, text)

@spec message(pid(), String.t()) :: :ok

Send a follow-up user message into a running live session.

run(provider, opts)

@spec run(
  module(),
  keyword()
) :: {:ok, ReqManagedAgents.SessionResult.t()} | {:error, term()}

start_link(provider, opts)

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

Start a long-lived session. Unlike run/2, it stays alive after a terminal for follow-ups.