Your First AXON Program
Let’s build a complete AXON program that analyzes documents. You’ll learn the core concepts while creating something functional.This guide assumes you’ve completed the installation and have at least one API key configured.
Step 1: Create Your First .axon File
Create a file calledanalyzer.axon:
analyzer.axon
1
Understand the persona block
The
persona defines the cognitive identity of your AI:domain: Areas of expertisetone: Communication styleconfidence_threshold: Minimum confidence level (0-1)
2
Understand the flow block
The Flows:
flow defines a pipeline of cognitive steps:- Take typed inputs (
input: Document) - Return typed outputs (
-> Summary) - Execute steps sequentially
- Pass data between steps
Step 2: Validate Your Syntax
Before running, check that your syntax is correct:Step 3: Compile to IR
Compile your AXON program to Intermediate Representation (IR):analyzer.ir.json - a JSON representation of your program that any backend can execute.
View the generated IR
View the generated IR
The IR is a JSON structure that captures the semantic meaning of your program:
Step 4: Execute Your Program
Run your AXON program with a specific backend:- Anthropic (Claude)
- OpenAI (GPT)
- Gemini
- Ollama (Local)
ANTHROPIC_API_KEY environment variable.Step 5: Add Constraints with Anchors
Now let’s add hard constraints that can never be violated:analyzer.axon
Step 6: Add Self-Healing with Refine
Make your program automatically retry and self-correct:analyzer.axon
refine directive:
- Automatically retries when confidence is too low
- Injects failure context back to the LLM
- Respects max attempts to prevent infinite loops
- Creates a closed feedback loop for self-healing
Step 7: Enable Execution Tracing
Get detailed insights into what happened during execution:analyzer.trace.json. View it with:
Example trace output
Example trace output
Advanced Example: Contract Analyzer
Here’s a production-ready example from the AXON repository:contract_analyzer.axon
Personas
Specialized domain expertise with citation requirements
Context
Session configuration for consistent behavior
Anchors
Hard constraints preventing hallucination
Types
Custom semantic types with ranges and optional fields
Tools
External capabilities with timeout configuration
Flows
Multi-step pipelines with data passing
Using the Python API
You can also use AXON programmatically:Common CLI Commands
Here’s a quick reference of useful commands:Error Hierarchy
AXON has a six-level error hierarchy:Next Steps
Language Reference
Deep dive into AXON’s syntax and semantics
Type System
Learn about epistemic types and subsumption
Examples
Real-world AXON programs
CLI Reference
Complete CLI documentation

