What is ReAct?
ReAct is a prompt engineering pattern that gives language models the ability to:- Think about what to do next (reasoning)
- Act by calling tools/functions
- Observe the results
- Re-reason based on observations
- Repeat until the task is complete
The Loop Implementation
The core loop is implemented inAgent.ts (lines 67-797). Here’s the simplified flow:
Step-by-Step Example
Let’s trace a real task: “Find the weather in Paris and send it to me on Telegram”Step 0: Pre-Task Simulation
Before entering the loop,SimulationEngine creates a plan:
Step 1: Reasoning
Prompt assembled by DecisionEngine:web_search("weather Paris current temperature")
Observation (saved to memory):
Step 2: Re-Reasoning
Prompt (Step 2):send_telegram(123456789, "Weather in Paris: 8°C...")
Observation (saved to memory):
Step 3: Completion
Prompt (Step 3):Loop Mechanics
Entry Conditions
The loop starts when:- An action is popped from the ActionQueue
Agent.runActionLoop()is called- The action status is
'pending'or'running'
Exit Conditions
The loop terminates when:- Natural completion: LLM sets
completed: true - Max steps reached: Default is 15 steps (configurable via
maxStepsPerAction) - Max messages sent: Default is 10 (configurable via
maxMessagesPerAction) - Hard timeout: 30 minutes (configurable via
actionTimeoutMs) - Cancellation: User or system cancels the action
Step Budget (Dynamic)
OrcBot uses an LLM-based Task Complexity Classifier to adjust step budgets dynamically:Memory Scope
Each step’s observations are saved with the action ID:- See its own progress within the current task
- Filter out unrelated memories from other actions
- Clean up step memories after task completion
Step History Compaction
When step count exceeds 10, OrcBot automatically compacts history:Guardrails
Before each tool execution,DecisionPipeline applies safety checks:
1. Deduplication
Prevents repeated identical tool calls within the same action:2. Loop Detection
Blocks repetitive patterns (e.g., web_search → browser_navigate → web_search):3. Cross-Channel Send Protection
Non-admin tasks can’t send to other channels:4. Autonomy Delivery Policy
Heartbeat tasks can only send to allowed channels:Termination Review
Before acceptingcompleted: true, OrcBot runs a termination review to prevent premature exits:
| Code | Meaning | Fix |
|---|---|---|
NO_SEND | No user-visible reply sent for a channel task | Send a message before completing |
UNSENT_RESULTS | Deep tool output exists after the last message | Send final results summary |
ACK_ONLY | Only status updates sent, no substantive content | Deliver concrete findings |
ERROR_UNRESOLVED | Tool errors without recovery/explanation | Retry or explain failure |
Transparency Nudges
If the agent works silently for too long, the prompt injects a nudge:Special Loop Modes
Heartbeat Loop
Autonomous tasks (source: 'autonomy') skip redundant context loading:
Time Capsule Mode
High-intensity tasks with relaxed limits:Lean Mode
Skip expensive context retrieval for simple tasks:Debugging the Loop
To trace loop execution: 1. Enable verbose logs:Performance Notes
Token costs per step:- System prompt: ~2,500 tokens (cached after step 1)
- Step history: ~500-2,000 tokens (grows with step count, compacted at 10+)
- Tool output: ~500-5,000 tokens (truncated if > 10 KB)
- LLM response: ~200-500 tokens
- Use
compactSkillsPrompt: trueto reduce skills list by 60% - Enable step compaction (default threshold: 10 steps)
- Set
memoryContentMaxLengthto 1500 (default) to truncate large observations - Use lean mode for simple tasks
Further Reading
- Decision Pipeline — Guardrails and safety layers
- Memory System — How observations are stored and retrieved
- Skills System — Available tools and how to add new ones
- Architecture — Overall system design