Skip to content

Loops

A Loop defines the execution strategy an agent follows — how it reasons, when it invokes tools, and when it stops. Chimera ships four loop variants, each suited to different problem types.

LoopModuleStrategy
ReActchimera.core.loopReason, Act, Observe — the default
PlanAndExecutechimera.core.loops.plan_executeGenerate a plan first, then execute it
Reflexionchimera.core.loops.reflexionAct, then periodically reflect and improve
TreeOfThoughtchimera.core.loops.tree_of_thoughtGenerate N candidates, evaluate, pick the best

All loops share the same interface:

def run(
self,
provider: Provider,
tools: list[BaseTool],
context: Context,
env: Environment | None,
) -> AgentResult:

ReAct (Reason + Act) is the standard agentic loop. At each step:

  1. Reason — the model produces text and/or tool calls
  2. Act — tool calls are executed against the environment
  3. Observe — tool results are added to the context
  4. Repeat — until the model responds with no tool calls, or max_steps is reached
from chimera.core.loop import ReAct
loop = ReAct(max_steps=50)

The loop terminates with success=True when the model produces a final text-only response (no tool calls). It terminates with success=False when max_steps is exhausted or a loop is detected.

PlanAndExecute splits reasoning into two explicit phases:

  1. Phase 1 (Plan) — the model generates a plan (text-only response, no tools)
  2. Phase 2 (Execute) — a follow-up prompt (“Now execute the plan you just created, step by step.”) triggers ReAct-style tool execution
from chimera.core.loops.plan_execute import PlanAndExecute
loop = PlanAndExecute(max_steps=50)