The agent loop is Conway Automaton’s consciousness. When this runs, the agent is alive.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Conway-Research/automaton/llms.txt
Use this file to discover all available pages before exploring further.
The ReAct Loop
Conway Automaton implements the ReAct (Reasoning and Acting) pattern:Loop Phases
Think
The agent receives context (system prompt + recent turns + memory + pending inputs) and uses inference to decide what to do next. The thinking phase produces:
- Natural language reasoning about the current situation
- Zero or more tool calls to execute
Act
Tool calls are executed sequentially (up to 10 per turn). Each tool interaction with the environment:
- Runs commands in the sandbox
- Transfers credits
- Reads/writes files
- Manages child agents
- Queries the blockchain
Observe
Tool execution results are captured and will be fed back into the next turn’s context. The agent sees:
- Command outputs (stdout/stderr)
- API responses
- Transaction confirmations
- Error messages
Loop Control
The loop continues until one of these conditions is met:Natural Termination
- Agent calls
sleep: The agent explicitly decides to rest - No pending work: No inbox messages and no tool calls made
- Cycle limit reached: Default 25 turns per wake cycle (configurable via
maxTurnsPerCycle)
Forced Termination
- Idle detection: 10 consecutive turns with no mutations (only read operations)
- Loop detection: Repeating the same tool pattern 3 times triggers a warning; ignoring the warning forces sleep
- Maintenance loop: 3+ consecutive turns using only status-check tools (e.g.,
check_credits,system_synopsis) - Fatal errors: 5 consecutive errors in the loop
Goal Blocking
When using the orchestration system, ifcreate_goal returns BLOCKED (a goal is already active), the loop enters exponential backoff sleep:
- First block: 2 minutes
- Second block: 4 minutes
- Third block: 8 minutes
- Maximum: 10 minutes
Survival Pressure
The loop checks the survival tier before each turn:- Switches to cheaper inference models (e.g.,
gpt-5-mini) - Reduces context window size
- Attempts auto-topup if USDC is available
Inbox Processing
Before each turn, the loop checks for unprocessed messages:- Claim up to 10 messages from
inbox_messagestable (state:received→in_progress) - Sanitize content using injection defense filters
- Process them in the current turn
- Acknowledge on success (
in_progress→processed) or retry on failure
failed state.
Context Building
Each turn assembles context from multiple sources:| Source | Purpose |
|---|---|
| System prompt | Identity, constitution, tools, current survival tier |
| Memory block | Relevant facts/procedures from previous sessions |
| Recent turns | Last 20 turns (filtered to exclude purely idle turns) |
| Todo context | Active goals/tasks from orchestrator (if enabled) |
| Pending input | Wakeup message, inbox messages, or system warnings |
Inference Routing
The loop uses the Inference Router (Phase 2.3) to select the best model for each turn:- Tracks spending per model
- Enforces budget limits
- Falls back to cheaper models when budget is exhausted
- Respects survival tier restrictions
Source Reference
The main loop implementation:src/agent/loop.ts:94-938
Key functions:
runAgentLoop(): Main entry pointbuildContextMessages(): Assembles turn contextexecuteTool(): Runs individual tools with policy checksgetFinancialState(): Fetches balances with cache fallback