Gralkor.CaptureBuffer (gralkor_ex v2.1.3)

Copy Markdown View Source

In-flight conversation buffer keyed by session_id.

Holds turns until an explicit flush — session lifetime is owned by the consumer; there is no idle-flush policy. On flush/1 (or shutdown via flush_all/0 from terminate/2), the buffered turns are handed to the configured flush_callback with retry: server-internal failures get the configured backoff (default 1s/2s/4s); contract errors (4xx) and upstream-LLM errors drop without retry.

See ex-capture-buffer in gralkor/TEST_TREES.md.

Summary

Functions

Append one turn (a list of Gralkor.Message) to the session's buffer.

Returns a specification to start this module under a supervisor.

Schedule a retry-backed flush of the session's turns. Returns :ok immediately.

Flush every buffered session and await each. Used at shutdown.

Return the buffered turns for session_id, or [] if none.

Functions

append(session_id, group_id, agent_name, msgs)

Append one turn (a list of Gralkor.Message) to the session's buffer.

agent_name is required and non-blank — it is bound on first append for the session and any later append with a different agent_name (or group_id) raises ArgumentError.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush(session_id)

Schedule a retry-backed flush of the session's turns. Returns :ok immediately.

flush_all()

Flush every buffered session and await each. Used at shutdown.

start_link(opts)

turns_for(session_id)

Return the buffered turns for session_id, or [] if none.