@agentlib/reasoning
Reasoning engines for AgentLIB — powerful strategies for agent decision-making and problem-solving.Installation
Overview
The@agentlib/reasoning package provides five built-in reasoning engines:
- ReAct: Reason + Act pattern for tool-using agents
- Chain-of-Thought (CoT): Step-by-step reasoning before responding
- Planner: Task decomposition and sequential execution
- Reflect: Self-reflection and answer revision
- Autonomous: Fully autonomous multi-step reasoning
Quick Start
Reasoning Engines
ReAct Engine
The ReAct (Reason + Act) pattern alternates between reasoning and action steps. Perfect for tool-using agents.- Receives user input
- Generates thought + action (tool call)
- Executes tool and observes result
- Repeats until final answer
- Returns response
- Agents with tools
- Question answering with external data
- Research and information gathering
Chain-of-Thought Engine
The Chain-of-Thought (CoT) engine guides the model through explicit reasoning steps before providing a final answer.- Breaks down the problem
- Generates intermediate reasoning steps
- Synthesizes final answer
- Math problems
- Logical reasoning
- Complex question answering
- Educational applications
Planner Engine
The Planner engine decomposes tasks into subtasks and executes them sequentially.- Analyzes the user request
- Generates a plan with subtasks
- Executes tasks in order (respecting dependencies)
- Synthesizes results into final answer
type: 'plan'- The generated plantype: 'tool_call'- Each subtask executiontype: 'tool_result'- Subtask resultstype: 'response'- Final answer
- Complex multi-step tasks
- Research projects
- Content creation workflows
- Project management
Reflect Engine
The Reflect engine generates an answer, critiques it, and optionally revises it.- Generates initial answer
- Reflects on the answer quality
- If revision needed, generates improved version
- Repeats up to maxRevisions times
- Returns final answer
type: 'response'- Initial answertype: 'reflection'- Self-critiquetype: 'response'- Revised answer (if needed)
- High-quality content generation
- Code review and improvement
- Essay writing
- Critical thinking tasks
Autonomous Engine
The Autonomous engine runs fully independently, deciding when to use tools, when to think, and when to respond.- Agent decides its own action strategy
- Can call multiple tools, think, or respond
- Continues until it determines task is complete
- Returns final answer
- Open-ended tasks
- Complex problem solving
- Research and exploration
- When you want minimal guidance
Auto-Registration
All engines are automatically registered when you import@agentlib/reasoning:
Custom Reasoning Engines
You can create your own reasoning engines:Reasoning Steps
All engines emit reasoning steps that you can observe:thought- Reasoning/thinking stepplan- Generated plan with subtaskstool_call- Tool invocationtool_result- Tool execution resultreflection- Self-critiqueresponse- Final or intermediate answer
Comparing Engines
| Engine | Best For | Complexity | Tool Use | Iterations |
|---|---|---|---|---|
| ReAct | Tool-heavy tasks | Medium | Yes | Multi |
| CoT | Reasoning tasks | Low | No | Single |
| Planner | Multi-step projects | High | Yes | Multi |
| Reflect | Quality improvement | Medium | No | Multi |
| Autonomous | Open-ended tasks | High | Yes | Multi |
Requirements
- Node.js: >= 18.0.0
- Dependencies:
@agentlib/core(workspace)
Exports
Engines
ReactEngineChainOfThoughtEnginePlannerEngineReflectEngineAutonomousEngine
Types
ReactEngineConfigChainOfThoughtEngineConfigPlannerEngineConfigReflectEngineConfigAutonomousEngineConfig
Related Packages
- @agentlib/core - Core reasoning types and registry
- @agentlib/orchestrator - Multi-agent orchestration