Canonical representation of a single LLM turn.
A turn captures the normalized response shape consumed by strategies and directives:
- Response classification (
:tool_callsor:final_answer) - Ordered multimodal content, extracted text, and optional thinking content
- Normalized tool calls
- Usage/model metadata
- Optional executed tool results
Summary
Functions
Returns the ordered visible content for assistant-message projection.
Projects the turn into an assistant message compatible with ReqLLM context.
Builds a tools map from action modules.
Executes a tool by name using a tools map and returns raw action output.
Executes an action module directly without registry lookup.
Extracts text from a content value (not wrapped in response structure).
Extracts text content from an LLM response or content value.
Formats a raw tool execution result into tool message content.
Builds a turn from a ReqLLM response.
Builds a turn from a map that is already in classified result shape.
Returns generated image content parts in response order.
Returns true when the turn requests tool execution.
Normalizes parameters from LLM format to schema-compliant format.
Returns text for text-only turns or ordered content parts for multimodal turns.
Executes normalized tool calls and returns normalized tool results.
Executes all requested tools for the turn and returns the updated turn.
Converts a turn to a plain result map for public action/plugin outputs.
Projects tool results into role: :tool messages.
Returns a copy of the turn with normalized tool results attached.
Types
@type execute_opts() :: [ timeout: pos_integer() | nil, tools: tools_map() | [module()] | module() | nil, telemetry_metadata: map() ]
@type response_type() :: :tool_calls | :final_answer
@type run_opts() :: [ timeout: pos_integer() | nil, tools: map() | [module()] | module() | nil ]
@type t() :: %Jido.AI.Turn{ content_parts: [ReqLLM.Message.ContentPart.t()], finish_reason: atom() | nil, message_metadata: map(), model: String.t() | nil, reasoning_details: list() | nil, text: String.t(), thinking_content: String.t() | nil, tool_calls: [term()], tool_results: [tool_result()], type: response_type(), usage: map() | nil }
@type tool_result() :: %{ id: String.t(), name: String.t(), content: tool_result_content(), raw_result: execute_result() }
@type tool_result_content() :: String.t() | [ReqLLM.Message.ContentPart.t()]
Functions
@spec assistant_content(t()) :: String.t() | [ReqLLM.Message.ContentPart.t()]
Returns the ordered visible content for assistant-message projection.
@spec assistant_message(t()) :: ReqLLM.Message.t()
Projects the turn into an assistant message compatible with ReqLLM context.
Builds a tools map from action modules.
@spec execute(String.t(), map(), map(), execute_opts()) :: execute_result()
Executes a tool by name using a tools map and returns raw action output.
@spec execute_module(module(), map(), map(), execute_opts()) :: execute_result()
Executes an action module directly without registry lookup.
Extracts text from a content value (not wrapped in response structure).
Extracts text content from an LLM response or content value.
This supports the canonical response/content normalization shapes used across actions and strategy flows.
@spec format_tool_result_content(execute_result() | {:ok, term()} | {:error, term()}) :: tool_result_content()
Formats a raw tool execution result into tool message content.
@spec from_response( map() | ReqLLM.Response.t() | t(), keyword() ) :: t()
Builds a turn from a ReqLLM response.
Options:
:model- Override model from the response payload
Builds a turn from a map that is already in classified result shape.
@spec images(t()) :: [ReqLLM.Message.ContentPart.t()]
Returns generated image content parts in response order.
Returns true when the turn requests tool execution.
Normalizes parameters from LLM format to schema-compliant format.
@spec result(t()) :: String.t() | [ReqLLM.Message.ContentPart.t()]
Returns text for text-only turns or ordered content parts for multimodal turns.
@spec run_tool_calls([term()], map(), run_opts()) :: {:ok, [tool_result()]}
Executes normalized tool calls and returns normalized tool results.
Executes all requested tools for the turn and returns the updated turn.
Converts a turn to a plain result map for public action/plugin outputs.
@spec tool_messages(t() | [map()]) :: [ReqLLM.Message.t()]
Projects tool results into role: :tool messages.
Returns a copy of the turn with normalized tool results attached.