Introducing a Python-Based Reasoning Engine for Deterministic AI
In the age of large language models (LLMs), there’s a growing need for deterministic systems that enforce rules and constraints while reasoning about information. We’ve developed a Python-based reasoning and validation framework that bridges the gap between traditional rule-based logic and modern AI capabilities, inspired by frameworks like Pydantic.
This approach is designed for developers and non-technical experts alike, making it easy to build complex rule engines that translate natural language instructions into enforceable code. Our fine-tuned model automates the creation of rules while ensuring human oversight for quality and conflict detection. The result? Faster implementation of rule engines, reduced developer overhead, and flexible extensibility across domains.
The Framework at a Glance
Our system consists of five core components:
- Data Structure: The foundational representation of entities and their attributes.
- Rules: Constraints or logic that govern the system.
- Reasoning Framework: The engine that processes data against rules to derive outcomes.
- Agent: The mechanism that interacts with and manipulates the system.
- State Machine: A tracker of the system’s current and historical states.
To analogize, this framework operates like a game of chess:
- The Data Structure is the chessboard and pieces.
- The Rules define how each piece can move.
- The Reasoning Framework is the player strategizing moves.
- The Agent moves the pieces.
- The State Machine records the state of the board after each turn.
Our framework supports two primary use cases:
- Validation Engines: Stateless systems that validate data against rules.
- Reasoning Engines: Stateful systems that navigate problems and make decisions.
Key Features and Benefits
- Natural Language Rule Creation: Non-technical users can input rules as plain text, which are then converted into Python structures for developer approval.
- Conflict Detection: Automatically flags contradictory rules during input, streamlining validation.
- Extensibility Across Use Cases: From logistics to compliance, the framework adapts to diverse business scenarios.
- Developer Efficiency: Cuts development time by 5x through automated rule generation and validation.
Case Studies
Validation Engine: Ensuring Compliance
A mining company needed to validate employee qualifications based on age, region, and role.
Example Data Structure:
jsonCopy code{
"employees": [
{ "name": "Sarah", "age": 25, "role": "Manager", "documents": ["safe_handling_at_work", "heavy_lifting"] },
{ "name": "John", "age": 17, "role": "Laborer", "documents": ["heavy_lifting"] }
]
}
Rules:
jsonCopy code{
"rules": [
{ "type": "min_age", "parameters": { "min_age": 18 } },
{ "type": "dozer_operator", "parameters": { "document_type": "dozer_qualification" } }
]
}
Outcome:
The system flagged violations, such as employees under 18 or missing required qualifications, ensuring compliance with organizational rules.
Reasoning Engine: Solving the River Crossing Puzzle
The classic river crossing puzzle demonstrates the engine’s reasoning capabilities.
Problem Setup:
A farmer must ferry a goat, a wolf, and a cabbage across a river, adhering to specific constraints (e.g., the goat cannot be left alone with the cabbage).
Steps:
- Define the entities (farmer, goat, wolf, cabbage).
- Translate constraints into rules.
- Use the reasoning engine to compute a solution.
Output:
The engine generated a solution in 0.0003 seconds, showcasing its efficiency in navigating complex logic.
Advanced Features: Dynamic Rule Expansion
The system supports real-time rule adjustments. For instance, adding a “wolf cannot be left with a chicken” constraint introduces a conflict. By extending rules (e.g., allowing the farmer to carry two items), the engine dynamically resolves previously unsolvable scenarios.
Sample Code Snippet:
pythonCopy codeclass CarryingCapacityRule(Rule):
def evaluate(self, state):
items_moved = sum(1 for item in ['wolf', 'goat', 'cabbage', 'chicken'] if getattr(state, item) == state.farmer)
return items_moved <= 2
def get_description(self):
return "Farmer can carry up to two items at a time"
Result:
The adjusted engine solved the puzzle in three moves, down from seven, while maintaining rule integrity.
Collaborative UI for Rule Creation
Our user interface empowers domain experts to define rules without writing code. Developers validate these rules, which are then seamlessly integrated into the system.
Visual Workflow:
- Input rules in natural language.
- AI translates them into Python.
- Developers validate and approve.
- The system runs rules in real time.