PtcRunner.SubAgent.CompiledAgent (PtcRunner v0.4.1)
View SourceA compiled SubAgent with pre-derived PTC-Lisp logic.
Created via SubAgent.compile/2, this struct stores PTC-Lisp code derived
once by an LLM. The compiled agent can then be executed many times without
further LLM calls, making it efficient for processing many items with
deterministic logic.
Use Cases
- Processing batch data with consistent logic (e.g., scoring reports)
- Agents with pure tools that don't require LLM decisions at runtime
- Workflows where the logic is derived once and reused many times
Limitations
CompiledAgents can only use pure Elixir tools. They cannot include:
LLMTool- requires LLM at execution timeSubAgentTool- requires LLM at execution time
See SubAgent.compile/2 for compilation details.
Fields
source- Inspectable PTC-Lisp source code (String)signature- Functional contract copied from agent (String)execute- Pre-bound executor function(map() -> result)metadata- Compilation metadata (seemetadata/0)field_descriptions- Descriptions for signature fields (Map, optional)
Examples
Compile and execute:
iex> tools = %{"double" => fn %{n: n} -> n * 2 end}
iex> agent = PtcRunner.SubAgent.new(
...> prompt: "Double the input number {{n}}",
...> signature: "(n :int) -> {result :int}",
...> tools: tools,
...> max_turns: 1
...> )
iex> mock_llm = fn _ -> {:ok, ~S|(return {:result (ctx/double {:n ctx/n})})|} end
iex> {:ok, compiled} = PtcRunner.SubAgent.compile(agent, llm: mock_llm, sample: %{n: 5})
iex> compiled.signature
"(n :int) -> {result :int}"
iex> compiled.source
~S|(return {:result (ctx/double {:n ctx/n})})|
iex> result = compiled.execute.(%{n: 10})
iex> result.return.result
20
Summary
Functions
Wraps a compiled agent as a callable tool.
Types
@type metadata() :: %{ compiled_at: DateTime.t(), tokens_used: non_neg_integer(), turns: pos_integer(), llm_model: String.t() | nil }
Metadata captured during compilation.
Fields:
compiled_at- UTC timestamp when compilation completedtokens_used- Total tokens consumed during compilationturns- Number of LLM turns used during compilationllm_model- Model identifier if available from LLM response
@type t() :: %PtcRunner.SubAgent.CompiledAgent{ execute: (map() -> PtcRunner.Step.t()), field_descriptions: map() | nil, metadata: metadata(), signature: String.t() | nil, source: String.t() }
CompiledAgent struct.
Fields:
source- PTC-Lisp program source codesignature- Type signature for inputs/outputsexecute- Function that executes the program(map() -> Step.t())metadata- Compilation metadatafield_descriptions- Descriptions for signature fields
Functions
@spec as_tool(t()) :: %{ type: :compiled, execute: (map() -> PtcRunner.Step.t()), signature: String.t() | nil }
Wraps a compiled agent as a callable tool.
The resulting tool can be used in parent agents. When called, it executes the compiled PTC-Lisp program without making any LLM calls.
Examples
iex> tools = %{"double" => fn %{n: n} -> n * 2 end}
iex> agent = PtcRunner.SubAgent.new(
...> prompt: "Double {{n}}",
...> signature: "(n :int) -> {result :int}",
...> tools: tools,
...> max_turns: 1
...> )
iex> mock_llm = fn _ -> {:ok, ~S|(return {:result (ctx/double {:n ctx/n})})|} end
iex> {:ok, compiled} = PtcRunner.SubAgent.compile(agent, llm: mock_llm, sample: %{n: 1})
iex> tool = PtcRunner.SubAgent.CompiledAgent.as_tool(compiled)
iex> tool.type
:compiled
iex> result = tool.execute.(%{n: 5})
iex> result.return.result
10