# `PtcRunner.SubAgent.Loop.TextMode`
[🔗](https://github.com/andreasronge/ptc_runner/blob/main/lib/ptc_runner/sub_agent/loop/text_mode.ex#L1)

Unified execution loop for text output mode.

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

| Tools? | Return type | Behavior |
|--------|-------------|----------|
| No  | `:string` or none | Raw text response (single LLM call) |
| No  | complex type | JSON response (validated against signature) |
| Yes | `:string` or none | Tool loop → text answer |
| Yes | complex type | Tool loop → JSON answer |

This module replaces the former `JsonMode` and `ToolCallingMode`.

# `preview_prompt`

```elixir
@spec preview_prompt(PtcRunner.SubAgent.Definition.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`

```elixir
@spec run(PtcRunner.SubAgent.Definition.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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
