PtcRunner.SubAgent.Loop.TextMode (PtcRunner v0.9.0)

Copy Markdown View Source

Unified execution loop for text output mode.

Text mode auto-detects the appropriate behavior from two signals:

Tools?Return typeBehavior
No:string or noneRaw text response (single LLM call)
Nocomplex typeJSON response (validated against signature)
Yes:string or noneTool loop → text answer
Yescomplex typeTool loop → JSON answer

This module replaces the former JsonMode and ToolCallingMode.

Summary

Functions

Generate a preview of the text mode prompts.

Execute a SubAgent in text mode.

Functions

preview_prompt(agent, context)

@spec preview_prompt(PtcRunner.SubAgent.t(), map()) :: %{
  system: String.t(),
  user: String.t(),
  tool_schemas: [map()],
  schema: map() | nil
}

Generate a preview of the text mode prompts.

Returns the system and user messages that would be sent to the LLM, plus tool schemas and JSON schema when applicable.

run(agent, llm, state)

@spec run(PtcRunner.SubAgent.t(), term(), map()) ::
  {:ok, PtcRunner.Step.t()} | {:error, PtcRunner.Step.t()}

Execute a SubAgent in text mode.

Auto-detects the variant based on tools and return type, then dispatches to the appropriate execution path.