- TypeScript 84.4%
- JavaScript 15.6%
|
|
||
|---|---|---|
| src | ||
| tests | ||
| .gitignore | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
Reasoning Tool
A specialized AI tool for systematic reasoning and analysis using dedicated reasoning models like o1, o3-mini, and Claude 4. This tool follows the ReWOO (Reasoning Without Observation) pattern to provide cost-efficient, strategic reasoning capabilities for complex problems.
Overview
The reasoning tool allows AI agents to perform deep analysis and multi-step reasoning only when needed, rather than using expensive reasoning models for all operations. It's designed to improve performance on complex tasks like those in the GAIA benchmark while maintaining cost efficiency.
Key Features
- Strategic Model Selection: Automatically selects the best reasoning model based on task type
- Multiple Reasoning Types: Supports general, STEM, coding, and analysis reasoning
- Confidence Scoring: Provides confidence metrics for reasoning quality
- Structured Output: Returns step-by-step reasoning breakdown
- Error Handling: Robust error handling with detailed feedback
- Cost Optimization: Uses reasoning models only when complex analysis is required
Usage
Basic Usage
import { reasoningToolDefinition } from 'reasoning-tool';
// Register with agent
toolRegistry.registerTool('reasoning', reasoningToolDefinition);
Input Parameters
problem(required): The problem or question requiring reasoningcontext(optional): Additional context or background informationreasoningType(optional): Type of reasoning - 'general', 'stem', 'coding', 'analysis'modelPreference(optional): Specific reasoning model to usemaxSteps(optional): Maximum number of reasoning stepsoutputFormat(optional): Desired output format - 'plan', 'analysis', 'solution'
Output Structure
{
reasoning: string; // The complete reasoning process
conclusion: string; // Final conclusion or recommendation
confidence: number; // Confidence score (0-1)
reasoningSteps: string[]; // Step-by-step breakdown
recommendedActions?: string[]; // Suggested next actions
metadata: {
modelUsed: string; // Model that performed reasoning
tokenUsage: number; // Tokens consumed
reasoningTime: number; // Processing time in ms
}
}
Model Selection Strategy
The tool automatically selects appropriate models based on reasoning type:
- STEM Problems: o3-mini → o1 → default model
- Coding Tasks: Claude 4 → o1 → default model
- Analysis Tasks: Claude 3.7 Sonnet → default model
- General Reasoning: o1 → default model
When to Use
The reasoning tool is particularly effective for:
- Complex Multi-step Problems: Architecture design, system planning
- Failed Initial Approaches: When standard responses aren't sufficient
- GAIA-style Benchmark Tasks: Research and analysis problems
- Novel Problem Solving: Creative solutions requiring systematic thinking
- Decision Making: Weighing multiple complex options
Agent Integration
When integrated with an agent, it should be used for complex scenarios:
const agentDefinition = new AgentDefinition(
'Agent with Reasoning',
'AI agent with systematic reasoning capabilities',
'When faced with complex problems, multi-step tasks, or when initial approaches fail, use the reasoning tool to think through them systematically.',
['reasoning', 'other-tools...'],
'openai-gpt-4o'
);
Examples
Example 1: Architecture Design
Input: "Design a microservices architecture for an e-commerce platform handling 10M users"
Output: Systematic breakdown of scalability, data flow, service boundaries, and technology recommendations
Example 2: Problem Debugging
Input: "My React app is slow and users are complaining about performance"
Output: Step-by-step analysis of potential bottlenecks, measurement strategies, and optimization approaches
Performance Metrics
Success is measured by:
- GAIA Benchmark Improvement: Better scores on complex reasoning tasks
- Cost Efficiency: Reduced token usage vs. all-reasoning approaches
- Problem-solving Accuracy: Higher success rates on multi-step problems
- Appropriate Usage: Correct tool selection by agents
Development
Building
npm run build
Testing
node tests/test.js
Development Mode
npm run dev
Architecture
The tool consists of:
types.ts: TypeScript interfaces for inputs and outputsreasoning-tool.ts: Core reasoning logic and model selectionindex.ts: AI SDK tool definition and agent integrationtests/test.js: Basic functionality tests
Dependencies
ai: AI SDK for model interactionzod/v3: Schema validationagent-core: Core agent functionality
Notes
- Requires model registry access through experimental_context
- Uses
zod/v3for compatibility with AI SDK - Tool definition uses
as anytype assertion for TypeScript compatibility - Designed for cost-efficient reasoning in agent workflows