Jido.AI.TRMAgent
(Jido AI v2.1.0)
View Source
Base macro for TRM (Tiny-Recursive-Model) agents.
Wraps use Jido.Agent with Jido.AI.Reasoning.TRM.Strategy wired in,
plus standard state fields and helper functions.
Usage
defmodule MyApp.ReasoningAgent do
use Jido.AI.TRMAgent,
name: "reasoning_agent",
description: "Agent that improves answers through recursive reasoning",
max_supervision_steps: 10,
act_threshold: 0.95
endOptions
:name(required) - Agent name:description- Agent description (default: "TRM agent #{name}"):model- Model alias or direct model spec (default: :fast, resolved via Jido.AI.resolve_model/1):max_supervision_steps- Maximum supervision iterations before termination (default: 5):act_threshold- Confidence threshold for early stopping (default: 0.9):skills- Additional skills to attach to the agent (TaskSupervisorSkill is auto-included)
Generated Functions
reason/2,3- Async: sends prompt, returns{:ok, %Request{}}for later awaitingawait/1,2- Awaits a specific request's completionreason_sync/2,3- Sync convenience: sends prompt and waits for resultstrategy_opts/0- Returns the strategy options (for CLI access)on_before_cmd/2- Captures request in state before processingon_after_cmd/3- Updates request result when done
Request Tracking
Each reason/2 call returns a Request struct that can be awaited:
{:ok, request} = MyAgent.reason(pid, "What is the best approach to solve X?")
{:ok, result} = MyAgent.await(request, timeout: 30_000)Or use the synchronous convenience wrapper:
{:ok, result} = MyAgent.reason_sync(pid, "What is the best approach to solve X?")State Fields
The agent state includes:
:model- The LLM model being used:requests- Map of request_id => request state (for concurrent tracking):last_request_id- ID of the most recent request:last_prompt- The most recent prompt (backward compat):last_result- The final result from the last completed reasoning (backward compat):completed- Boolean indicating if the last reasoning is complete (backward compat)
Task Supervisor
Each agent instance gets its own Task.Supervisor automatically started via the
Jido.AI.Plugins.TaskSupervisor. This supervisor is used for:
- LLM streaming operations
- Other async operations within the agent's lifecycle
Example
{:ok, pid} = Jido.AgentServer.start(agent: MyApp.ReasoningAgent)
# Async pattern (preferred for concurrent requests)
{:ok, request} = MyApp.ReasoningAgent.reason(pid, "What is the best approach to solve X?")
{:ok, result} = MyApp.ReasoningAgent.await(request)
# Sync pattern (convenience for simple cases)
{:ok, result} = MyApp.ReasoningAgent.reason_sync(pid, "What is the best approach to solve X?")TRM Workflow
TRM uses recursive reasoning to iteratively improve answers:
- Reasoning: Generate insights about the current answer
- Supervision: Evaluate the answer and provide feedback with a score
- Improvement: Apply feedback to generate a better answer
- Repeat until confidence threshold is met or max steps reached