Evaluation context for the Lisp interpreter.
Bundles the parameters that flow through recursive evaluation:
ctx: External data (read-only)user_ns: User namespace (mutable bindings fromdef)env: Lexical environment (variable bindings)tool_exec: Tool executor functionturn_history: Previous turn results for multi-turn loops
Limits
| Field | Default | Hard Cap | Purpose |
|---|---|---|---|
loop_limit | 1,000 | 10,000 | Max loop/recursion iterations |
max_print_length | 2,000 | — | Max chars per println call |
Summary
Types
Parallel map/calls execution record for tracing.
Tool call record for tracing.
Trace context for nested agent execution tracing.
Functions
Appends a pmap/pcalls execution record to the context.
Appends a print message to the context.
Appends a tool call record to the context.
Increments the iteration count and checks against the limit.
Merges two contexts, specifically combining prints, tool calls, and pmap calls. Used to merge results from parallel execution branches (pmap, pcalls).
Merges new bindings into the environment.
Creates a new evaluation context.
Sets a new loop limit, respecting the hard maximum.
Updates the user namespace in the context.
Types
@type pmap_call() :: %{ type: :pmap | :pcalls, count: non_neg_integer(), child_trace_ids: [String.t()], child_steps: [any()], timestamp: DateTime.t(), duration_ms: non_neg_integer(), success_count: non_neg_integer(), error_count: non_neg_integer() }
Parallel map/calls execution record for tracing.
Fields:
type::pmapor:pcallscount: Number of parallel taskschild_trace_ids: List of trace IDs from SubAgentTool executionstimestamp: When execution startedduration_ms: Total execution timesuccess_count: Number of successful executionserror_count: Number of failed executions
@type t() :: %PtcRunner.Lisp.Eval.Context{ budget: map() | nil, ctx: map(), env: map(), iteration_count: integer(), journal: map() | nil, loop_limit: integer(), max_print_length: pos_integer(), pmap_calls: [pmap_call()], pmap_timeout: pos_integer(), prints: [String.t()], summaries: %{required(String.t()) => String.t()}, tool_cache: map(), tool_calls: [tool_call()], tool_exec: (String.t(), map() -> term()), tools_meta: %{required(String.t()) => %{cache: boolean()}}, trace_context: trace_context(), turn_history: list(), user_ns: map() }
@type tool_call() :: %{ :name => String.t(), :args => map(), :result => term(), :error => String.t() | nil, :timestamp => DateTime.t(), :duration_ms => non_neg_integer(), optional(:child_trace_id) => String.t(), optional(:child_step) => term(), optional(:cached) => boolean() }
Tool call record for tracing.
Fields:
name: Tool nameargs: Arguments passed to toolresult: Tool resulterror: Error message if tool failedtimestamp: When tool was calledduration_ms: How long tool tookchild_trace_id: Trace ID of nested SubAgentTool execution (if any)
@type trace_context() :: %{ trace_id: String.t(), parent_span_id: String.t() | nil, depth: non_neg_integer() } | nil
Trace context for nested agent execution tracing.
Fields:
trace_id: Unique identifier for this trace sessionparent_span_id: Span ID of the parent operation (nil for root)depth: Nesting depth for visualization
Functions
Appends a pmap/pcalls execution record to the context.
Appends a print message to the context.
Long messages are truncated to max_print_length characters (default: 2000).
Appends a tool call record to the context.
Increments the iteration count and checks against the limit.
Merges two contexts, specifically combining prints, tool calls, and pmap calls. Used to merge results from parallel execution branches (pmap, pcalls).
Merges new bindings into the environment.
Creates a new evaluation context.
Options
:max_print_length- Max characters perprintlncall (default: 2000):budget- Budget info map for(budget/remaining)introspection (default: nil):pmap_timeout- Timeout in ms for each pmap task (default: 5000). Increase for LLM-backed tools.:trace_context- Trace context for nested agent tracing (default: nil)
Examples
iex> ctx = PtcRunner.Lisp.Eval.Context.new(%{}, %{}, %{}, fn _, _ -> nil end, [])
iex> ctx.user_ns
%{}
iex> ctx = PtcRunner.Lisp.Eval.Context.new(%{}, %{}, %{}, fn _, _ -> nil end, [], max_print_length: 500)
iex> ctx.max_print_length
500
iex> ctx = PtcRunner.Lisp.Eval.Context.new(%{}, %{}, %{}, fn _, _ -> nil end, [], budget: %{turns: 10})
iex> ctx.budget
%{turns: 10}
iex> ctx = PtcRunner.Lisp.Eval.Context.new(%{}, %{}, %{}, fn _, _ -> nil end, [], pmap_timeout: 60_000)
iex> ctx.pmap_timeout
60000
Sets a new loop limit, respecting the hard maximum.
Updates the user namespace in the context.