Skip to content

Loops

chimera.core.loop and chimera.core.loops ship the eight loop variants the framework uses to drive tool-augmented LLM agents. All of them accept a LoopConfig for cross-cutting concerns (permissions, events, audit, cancellation, hooks…) and behave identically when no config is supplied.

LoopModulePurpose
ReActchimera.core.loopReason→Act→Observe; the legacy default loop. Generator-based, supports iter_steps, PendingApproval, full LoopConfig surface.
AgentLoopchimera.core.agent_loopModern async-generator loop powering CodingAgent. Yields LoopEvents; integrates StreamingToolExecutor, AbortSignal, LoopState, RETRY_POLICIES.
RetryLoopchimera.core.loops.retryWrap any inner loop with score-and-retry.
LintFeedbackLoopchimera.core.loops.lint_feedbackInject linter / type-check feedback after each step.
PlanActLoopchimera.core.loops.plan_actTwo-phase: plan first (read-only tools), then act (full tools).
PlanAndExecutechimera.core.loops.plan_executePlan once, then execute the plan one bullet at a time.
Reflexionchimera.core.loops.reflexionSelf-reflect on failure and retry with a critique-augmented prompt.
TreeOfThoughtchimera.core.loops.tree_of_thoughtBranch-and-vote tree search across alternative continuations.
AutonomousLoopchimera.core.loops.autonomousLong-running loop for unattended runs (no per-step approval).

These are the two production loops. Most user-facing CLIs route through AgentLoop via CodingAgent; ReAct remains for direct Agent(provider, tools).run(...) calls and for the deprecated --legacy-react escape hatch.

TraitReActAgentLoop
StyleSync generator (iter_steps) + async_iter_stepsAsync generator (async for event in loop.run(...))
YieldsStepResultLoopEvent (typed event union)
Pending approvalStepResult.pending_approval (caller resolves)Hooked via permission_checker + permission_context
CancellationLoopConfig.cancellation (CancellationToken)abort_signal: AbortSignal
StreamingLoopConfig.handlerstream=True flag + StreamingToolExecutor
Hook integrationFires SessionStart / UserPromptSubmit / Stop[Failure] lifecycleFull pre/post tool-use surface via hook_executor + hook_matchers
Default in CLIchimera code --legacy-reactchimera code (default)
from chimera.core.loop import ReAct
from chimera.core.context import Context
from chimera.providers import create_provider
loop = ReAct(max_steps=20)
provider = create_provider("anthropic")
context = Context()
context.add_user("Refactor the auth module.")
result = None
for step in loop.iter_steps(provider, tools, context, env):
print(step.message.content)
if step.pending_approval:
step.pending_approval.approve()
if step.done:
result = step
break
from chimera.core.agent_loop import AgentLoop
from chimera.types import Message
loop = AgentLoop()
async for event in loop.run(
messages=[Message.user("Fix the failing test")],
tools=tools,
provider=provider,
system_prompt="You are a careful coding agent.",
max_turns=50,
):
if event.type.name == "text":
print(event.data, end="", flush=True)

Wraps any inner loop with a scorer and retries failed runs:

from chimera.core.loops.retry import RetryLoop, RetryAttempt
inner = ReAct(max_steps=20)
retry = RetryLoop(inner=inner, max_attempts=3, scorer=my_scorer)
result = retry.run(provider, tools, context, env)
# result.attempts: list[RetryAttempt]

Two-phase loop: read-only tool set during the plan phase, the full tool set during the act phase. The split tool set is exported as READ_ONLY_TOOLS from chimera.core.loops.plan_act.

Self-reflective loop: when a run fails, the loop prompts the model to critique the failure, then retries with the critique appended to the context — implementing the “Reflexion” prompting pattern.

Branches the conversation into N candidate continuations, scores each, and proceeds along the best branch. Useful for tasks where local greedy choice is unlikely to find the global optimum.

Long-running unattended loop with no per-step approval. Pair with PermissionRuleset(default=ALLOW) and a LoopDetector to keep runaway loops bounded.

Injects linter / type-check output between turns so the agent sees diagnostics in-band:

from chimera.core.loops.lint_feedback import LintFeedbackLoop
loop = LintFeedbackLoop(
lint_command=["ruff", "check", "."],
max_steps=20,
)
GoalLoop
General coding session, IDE-shapedAgentLoop (default in CodingAgent)
Programmatic Agent.run(...) with steps you can iterateReAct
Drive convergence with retriesRetryLoop wrapping ReAct/AgentLoop
Linter-driven iterationLintFeedbackLoop
Plan-first, then executePlanActLoop (two-phase) or PlanAndExecute
Unattended benchmarks / batch runsAutonomousLoop + LoopConfig(yolo_mode=True)
Self-critique on failureReflexion
Branch-and-vote searchTreeOfThought
from chimera.core.loop import ReAct
from chimera.core.agent_loop import AgentLoop
from chimera.core.loops import (
AutonomousLoop,
LintFeedbackLoop,
PlanActLoop,
PlanAndExecute,
READ_ONLY_TOOLS,
Reflexion,
RetryLoop,
TreeOfThought,
)