A Python package that analyses task complexity using DeepSeek (via Ollama) and routes tasks to OpenAI's O3-mini with appropriate reasoning effort levels.
The Reasoning Router implements an intelligent task routing system that:
- Analyses the complexity of input tasks using a decision tree approach
- Classifies tasks into LOW, MEDIUM, or HIGH complexity
- Routes tasks to OpenAI's O3-mini model with appropriate reasoning effort
Tasks are classified into three complexity levels:
LOW Complexity
- Single fact lookups (e.g., "What is the capital of France?")
- Basic arithmetic calculations
- Simple definition requests
- Yes/No questions about single facts
MEDIUM Complexity
- Comparing two specific things
- Explaining a single concept
- Following a clear process
- Basic cause and effect analysis
- Simple pros and cons
- Must NOT involve multiple domains or broad implications
HIGH Complexity
- Analysis across multiple domains
- Complex systems or trade-offs
- Broad societal/global implications
- Multiple stakeholder considerations
- Install dependencies:
pip install -r requirements.txt-
Install Ollama from ollama.ai
-
Pull the DeepSeek model:
ollama pull deepseek-r1:7b- Set up environment variables in
.env:
OPENAI_API_KEY=your_api_keyfrom reasoning_router import ReasoningRouter
async def main():
# Initialise the router
router = ReasoningRouter()
# Process a task
result = await router.process_task("What is the capital of France?")
# Access the results
print(f"Task: {result['task']}")
print(f"Complexity Level: {result['reasoning_level']}")
print(f"Analysis: {result['complexity_analysis']}")
print(f"Response: {result['response']}")
# Run with asyncio
import asyncio
asyncio.run(main())# LOW Complexity
result = await router.process_task("What is 2+2?")
# MEDIUM Complexity
result = await router.process_task("Compare cats and dogs as pets")
# HIGH Complexity
result = await router.process_task("Design a solution to climate change")The system uses two AI models:
-
DeepSeek (via Ollama): Analyses task complexity using a structured decision tree
- Runs locally through Ollama
- Uses pattern matching to extract complexity levels
- Provides detailed analysis of task characteristics
-
OpenAI O3-mini: Generates task responses
- Receives complexity level as reasoning effort parameter
- Adjusts response depth and detail based on complexity
The complexity analysis follows a strict decision tree:
- Check for LOW complexity criteria
- If not LOW, check for MEDIUM complexity criteria
- If not MEDIUM, check for HIGH complexity criteria
Run the test suite:
pytest tests/Example tests are provided in example.py.
reasoning_router/
├── __init__.py
├── router.py # Main implementation
├── tests/
│ ├── __init__.py
│ └── test_router.py
├── example.py # Usage examples
├── requirements.txt
└── README.md
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
MIT License - see LICENSE file for details