Manages context, memory, and tools for program execution.
ctx: External input data (read-only)memory: Mutable state passed through evaluationtools: Tool registry
See PtcRunner.SubAgent for usage in agentic loops.
Summary
Functions
Retrieves a value from context (external data).
Retrieves a value from memory (mutable state).
Creates a new context with external data, memory, tools, and optional turn history.
Sets a value in memory.
Types
@type t() :: %PtcRunner.Context{ ctx: map(), journal: map() | nil, memory: map(), tools: map(), turn_history: list() }
Context structure containing external data, memory, and tool registry.
journal: Optional journal map for(task)idempotent execution. When non-nil, task results are cached by ID. When nil, tasks execute without caching (with a trace warning).
Functions
Retrieves a value from context (external data).
Returns {:ok, nil} if key doesn't exist.
Examples
iex> ctx = PtcRunner.Context.new(%{"users" => [1, 2, 3]})
iex> PtcRunner.Context.get_ctx(ctx, "users")
{:ok, [1, 2, 3]}
iex> ctx = PtcRunner.Context.new()
iex> PtcRunner.Context.get_ctx(ctx, "missing")
{:ok, nil}
Retrieves a value from memory (mutable state).
Returns {:ok, nil} if key doesn't exist.
Examples
iex> ctx = PtcRunner.Context.new(%{}, %{"counter" => 42})
iex> PtcRunner.Context.get_memory(ctx, "counter")
{:ok, 42}
iex> ctx = PtcRunner.Context.new()
iex> PtcRunner.Context.get_memory(ctx, "missing")
{:ok, nil}
Creates a new context with external data, memory, tools, and optional turn history.
Examples
iex> ctx = PtcRunner.Context.new(%{"users" => [1, 2, 3]})
iex> ctx.ctx
%{"users" => [1, 2, 3]}
iex> ctx = PtcRunner.Context.new(%{}, %{"counter" => 0})
iex> ctx.memory
%{"counter" => 0}
Sets a value in memory.
Examples
iex> ctx = PtcRunner.Context.new()
iex> ctx = PtcRunner.Context.put_memory(ctx, "result", 100)
iex> ctx.memory
%{"result" => 100}