Turn state for a running agent.
Holds the streaming status, in-flight stream task, and the dissolved fields
from TurnState (index, checkpoints), StreamBuffer (text, thinking, calls),
and ToolRunner (running, results, loop_counts).
Summary
Functions
Add a completed tool call to the stream buffer.
Append a text delta to the stream buffer.
Append a thinking delta to the stream buffer.
Kill all in-flight tool task processes.
Cancel the in-flight stream task, if any.
Updates turn to continuation.
Mark a tool call as done. Returns {:ok, updated_turn} or :not_running.
Return a fresh turn state.
Resolve, wrap, and track a tool call. Returns {updated_turn, wrapped_fn}.
Push a checkpoint (current message-list length) onto the stack.
Rebuild checkpoints from a message list, preserving the current index.
Registers tool call.
Reset the stream buffer and tool runner to their initial state.
Updates turn to start.
Return true when all tool calls have completed.
Types
@type status() :: :idle | :streaming | :executing_tools
Status of the turn
@type t() :: %Planck.Agent.Turn{ buffer_calls: [map()], buffer_text: String.t(), buffer_thinking: String.t(), checkpoints: [non_neg_integer()], index: non_neg_integer(), loop_counts: %{optional({String.t(), non_neg_integer()}) => non_neg_integer()}, results: list(), running: %{required(String.t()) => %{name: String.t(), pid: pid()}}, status: status(), stream_ref: reference() | nil, stream_start: non_neg_integer(), stream_task: pid() | nil }
Turn information.
Functions
Add a completed tool call to the stream buffer.
Append a text delta to the stream buffer.
Append a thinking delta to the stream buffer.
@spec cancel_all_tools(t()) :: :ok
Kill all in-flight tool task processes.
@spec cancel_stream(t()) :: :ok
Cancel the in-flight stream task, if any.
Updates turn to continuation.
Mark a tool call as done. Returns {:ok, updated_turn} or :not_running.
@spec new() :: t()
Return a fresh turn state.
@spec prepare_call(t(), tools, agent_id, tool_call) :: {t(), (-> result)} when tools: %{required(tool_name) => Planck.Agent.Tool.t()}, agent_id: String.t(), tool_call: %{id: String.t(), name: tool_name, args: map()}, tool_name: String.t(), result: {:ok, String.t()} | {:ok, String.t(), %{ui: Planck.Agent.Tool.ui_content()}} | {:error, term()}
Resolve, wrap, and track a tool call. Returns {updated_turn, wrapped_fn}.
@spec push_checkpoint(t(), [Planck.Agent.Message.t()]) :: t()
Push a checkpoint (current message-list length) onto the stack.
@spec rebuild_checkpoints(t(), [Planck.Agent.Message.t()]) :: t()
Rebuild checkpoints from a message list, preserving the current index.
@spec register_call(t(), tool_call, pid()) :: t() when tool_call: %{id: String.t(), name: String.t(), args: map()}
Registers tool call.
Reset the stream buffer and tool runner to their initial state.
@spec start_turn(t(), pid(), reference(), [Planck.Agent.Message.t()]) :: t()
Updates turn to start.
Return true when all tool calls have completed.