Overview
TheAutonomousEngine implements an open-ended reasoning loop where the agent decides when it’s done by explicitly calling a finish tool. This is the most flexible engine, suitable for long-horizon tasks, research, and multi-step automation.
Unlike other engines that terminate based on tool calls or step counts, the autonomous engine runs until the agent signals completion.
When to Use
UseAutonomousEngine when:
- Tasks are open-ended with no fixed termination criteria
- The agent should decide when it has gathered enough information
- You need long-horizon reasoning (research, analysis, automation)
- Task complexity varies and can’t be predicted upfront
- You want maximum agent autonomy
Constructor
Configuration
Absolute maximum steps before forcing termination. Safety limit to prevent infinite loops.
Tool name the agent must call to signal completion. This tool is automatically injected into the tool list.
Description shown to the model for the finish tool. Default: “Signal that you have completed the task. Call this with your final answer.”
Usage Example
How It Works
- Inject Finish Tool: Automatically adds a
finishtool to the available tool list - Agent Loop:
- Model thinks and may call tools
- Tool results are appended to conversation
- Process repeats
- Termination: Loop ends when:
- Agent calls the
finishtool → uses itsresultargument as final output - Agent responds without any tool calls → uses response content as final output
maxStepsis reached → throws error
- Agent calls the
Finish Tool Schema
The automatically injected finish tool has this schema:Agent Usage Example
The model calls the finish tool to signal completion:Step Emissions
- ThoughtStep: Emitted when the model generates content (with or without tool calls)
- ToolCallStep / ToolResultStep: Emitted for all tool executions (including finish)
- ResponseStep: Emitted with the final result when finish is called
Error Handling
Max steps reached without finish call:Comparison with ReactEngine
| Feature | AutonomousEngine | ReactEngine |
|---|---|---|
| Termination | Agent calls finish tool | Model stops calling tools |
| Control | Agent-driven | Model-driven |
| Use Case | Open-ended tasks | Bounded tool-using tasks |
| Default maxSteps | 30 | 10 |
| Finish Tool | Required | Not applicable |
Best Practices
- Set appropriate maxSteps: Balance autonomy with safety
- Use token budgets: Prevent runaway costs in production
- Monitor step emissions: Track agent progress and detect loops
- Clear instructions: Tell the agent when/how to call finish
- Test thoroughly: Autonomous agents can be unpredictable
System Prompt Recommendation
Add clear termination instructions:String Alias
Implementation Reference
Source:packages/reasoning/src/engines/autonomous.ts:49