Iterative Reflective Expansion Algorithm
The IRE Algorithm is an advanced reasoning engine designed for high-complexity problem solving. It works in cycles:
Generate — Formulate multiple initial solution paths.
Simulate — Test each path through rapid scenario simulation.
Reflect — Identify flaws, gaps, and hidden assumptions.
Revise — Adapt reasoning strategies and refine solutions.
Each loop blends hypothesis testing with meta-cognitive feedback, allowing the system to learn from both wins and failures. Over successive iterations, IRE locks in on optimal strategies, evolving its reasoning model for sharper, faster, and more reliable decisions.
Workflow
Generate Initial Hypotheses Rapidly produce diverse reasoning paths. At this stage, quantity matters more than perfection.
Simulate Paths Virtually “run” each candidate path, testing feasibility, identifying weak links, and flagging potential bottlenecks.
Meta-Reflect Perform meta-cognitive analysis — detect flawed assumptions, missing constraints, or inefficient reasoning patterns.
Revise Paths Apply targeted corrections, restructure logic, and insert missing steps based on reflection insights.
Select Promising Paths Eliminate dead ends, keep only high-value candidates with strong potential.
Synthesize Solution Merge the strengths of multiple top-tier paths into a final, high-confidence answer.
Class Definition: IterativeReflectiveExpansion
IterativeReflectiveExpansion
agent
Agent
None
Crowe agent instance used for reasoning tasks
max_iterations
int
5
Maximum reasoning/reflection cycles
return_list
bool
False
Return conversation as a list of messages
return_dict
bool
False
Return conversation as a dictionary
prompt
str
GENERAL_REASONING_AGENT_SYS_PROMPT
System prompt for the agent
Core Methods
generate_initial_hypotheses
Produce the first set of reasoning strategies from the problem statement
simulate_path
Execute a reasoning path in a controlled simulation and score its effectiveness
meta_reflect
Perform meta-level analysis on observed weaknesses or logical failures
revise_path
Improve a path’s structure and accuracy based on reflection feedback
select_promising_paths
Choose the most viable strategies from the candidate pool
synthesize_solution
Merge top strategies into a single optimized solution
run
Execute the full IRE pipeline on a given problem
Example Use Case
Goal: Solve a mathematical problem.
from crowe import IterativeReflectiveExpansion
import re
import time
# Tiny validator for post-checks (optional)
def is_prime(n: int) -> bool:
if n < 2: return False
if n % 2 == 0: return n == 2
f = 3
while f * f <= n:
if n % f == 0: return False
f += 2
return True
ire = IterativeReflectiveExpansion(
max_iterations=4, # a bit more room to refine
return_dict=True, # get structured traces
prompt="Be methodical. Generate candidates, reflect, refine, and justify briefly."
)
t0 = time.time()
out = ire.run("What is the 40th prime number?")
elapsed = time.time() - t0
# Try to extract a number from the model’s final message
final_text = out.get("final") if isinstance(out, dict) else str(out)
m = re.search(r"\b(\d{2,6})\b", final_text or "")
guess = int(m.group(1)) if m else None
print({
"answer_text": final_text,
"numeric_guess": guess,
"is_prime_check": (is_prime(guess) if isinstance(guess, int) else None),
"iterations_used": out.get("iterations") if isinstance(out, dict) else None,
"elapsed_sec": round(elapsed, 3),
})
Conclusion
The Iterative Reflective Expansion framework transforms reasoning into an adaptive, evolving process. By combining hypothesis diversity, simulation-based validation, and meta-cognitive correction, Crowe can tackle problems that require deep reasoning, multi-step logic, and adaptive strategy refinement — without human intervention.
Last updated