Skip to main content

Overview

This example demonstrates advanced multi-step reasoning using AXON’s reason primitive, chain-of-thought reasoning, and self-healing validation. It shows how to break down complex problems into reasoning steps with confidence tracking and adaptive refinement.

Use Case

Solve complex problems requiring:
  • Multi-step logical reasoning
  • Chain-of-thought explanation
  • Recursive problem decomposition
  • Validation at each step
  • Self-correction when reasoning fails
  • Mathematical or logical proofs

Complete Code

multi_step_reasoning.axon

Key Components

Persona: LogicalReasoner

Defines a systematic reasoner:
  • Domains: Logic, mathematics, problem solving
  • Methodical tone: Step-by-step, careful
  • High threshold: 0.85 for sound reasoning
  • Chain-of-thought: Always show reasoning steps

Context: ReasoningMode

Configured for deep reasoning:
  • Session memory: Remember previous reasoning
  • Exhaustive depth: Thorough analysis
  • Large token budget: 8192 for complex reasoning
  • Moderate temperature: 0.4 balances consistency and creativity

Anchor: LogicalConsistency

Enforces logical rigor:
  • Requires: Logical validity (no invalid inferences)
  • High floor: 0.80 minimum confidence
  • Explicit uncertainty: Admit when conclusion uncertain
The LogicalConsistency anchor prevents invalid logical inferences. If the LLM attempts an unsound reasoning step, AXON’s self-healing runtime will retry with failure context.

Custom Types

Captures individual reasoning step:
  • Step number: Position in chain
  • Premise: Starting point (fact)
  • Conclusion: Derived result (fact)
  • Justification: Why conclusion follows (fact)
  • Confidence: How certain we are
Identifies logical contradictions.
Complete reasoning output:
  • All reasoning steps
  • Final conclusion
  • Any contradictions found
  • Overall confidence
  • Full reasoning trace

Flow: SolveComplexProblem

Six-step reasoning pipeline with validation: Step 1: DecomposeProblem
Decomposes complex problem into manageable sub-problems. Step 2: InitialAnalysis (Reasoning)
Uses explicit reasoning:
  • Depth 3: Moderate reasoning depth
  • Show work: Display reasoning steps
  • Chain-of-thought: Explicit reasoning trace
Validation
Ensures analysis quality. Step 3: StepByStepSolution (Deep Reasoning)
Deep reasoning (depth 5) to solve sub-problems. Step 4: CheckConsistency
Validates logical consistency. Validation
Retries if contradictions found. Step 5: FinalSynthesis (Reasoning)
Combines sub-solutions into final answer. Step 6: Synthesis and Memory
Combines all reasoning and stores in memory.

Usage

Run Reasoning Flow

Example Input

Example Output

Advanced Patterns

Mathematical Proof

Recursive Problem Solving

Debate-Style Reasoning

Causal Reasoning

Best Practices

1. Use Appropriate Reasoning Depth

2. Always Show Work for Complex Reasoning

3. Validate Logical Consistency

4. Use Session Memory for Multi-Turn Reasoning

5. Apply High Confidence Thresholds

6. Use Moderate Temperature

Contract Analyzer

Legal contract analysis with risk reasoning

Sentiment Analysis

Emotional reasoning and classification

Data Extraction

Extract structured data with validation
  • Flow — Reason operation and chain-of-thought
  • Anchor — Logical consistency constraints
  • Memory — Store reasoning chains
  • Persona — Define reasoning agents