Codex.Subagents (Codex SDK v0.14.0)

Copy Markdown View Source

Deterministic host-side helpers for working with subagent threads over app-server.

This module intentionally does not expose prompt-shaping operations such as spawning or delegating work. It only wraps host-callable thread inspection and polling behavior.

Summary

Functions

Polls a known child thread id until its latest turn reaches a terminal status.

Returns true when the thread/source carries an explicit parent-child spawn link.

Lists spawned child threads for a known parent thread id.

Lists subagent threads using thread/list.

Returns the parent thread id for a spawned child thread source, if present.

Reads a known subagent thread using thread/read.

Parses the typed source metadata for a thread map or raw source payload.

Types

terminal_turn_status()

@type terminal_turn_status() :: :completed | :failed | :interrupted

thread_map()

@type thread_map() :: map()

Functions

await(conn, thread_id, opts \\ [])

@spec await(pid(), String.t(), keyword()) ::
  {:ok, terminal_turn_status()} | {:error, term()}

Polls a known child thread id until its latest turn reaches a terminal status.

This uses repeated thread/read(include_turns: true) calls and returns the latest terminal turn status.

child_thread?(value)

@spec child_thread?(
  thread_map()
  | Codex.Protocol.SessionSource.t()
  | map()
  | String.t()
  | atom()
  | nil
) ::
  boolean()

Returns true when the thread/source carries an explicit parent-child spawn link.

children(conn, parent_thread_id, opts \\ [])

@spec children(pid(), String.t(), keyword()) ::
  {:ok, [thread_map()]} | {:error, term()}

Lists spawned child threads for a known parent thread id.

list(conn, opts \\ [])

@spec list(
  pid(),
  keyword()
) :: {:ok, [thread_map()]} | {:error, term()}

Lists subagent threads using thread/list.

This defaults source_kinds to [:sub_agent]. When you need pagination or other raw thread/list response metadata, use Codex.AppServer.thread_list/2 directly.

parent_thread_id(value)

@spec parent_thread_id(
  thread_map()
  | Codex.Protocol.SessionSource.t()
  | map()
  | String.t()
  | atom()
  | nil
) :: String.t() | nil

Returns the parent thread id for a spawned child thread source, if present.

read(conn, thread_id, opts \\ [])

@spec read(pid(), String.t(), keyword()) :: {:ok, thread_map()} | {:error, term()}

Reads a known subagent thread using thread/read.

source(source)

Parses the typed source metadata for a thread map or raw source payload.