Skip to main content

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 called analyzer.axon:
analyzer.axon
1

Understand the persona block

The persona defines the cognitive identity of your AI:
  • domain: Areas of expertise
  • tone: Communication style
  • confidence_threshold: Minimum confidence level (0-1)
2

Understand the flow block

The flow defines a pipeline of cognitive steps:
Flows:
  • 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:
Always use axon check during development to catch errors early. It runs the lexer, parser, and type checker without executing anything.

Step 3: Compile to IR

Compile your AXON program to Intermediate Representation (IR):
This creates analyzer.ir.json - a JSON representation of your program that any backend can execute.
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:
Requires ANTHROPIC_API_KEY environment variable.

Step 5: Add Constraints with Anchors

Now let’s add hard constraints that can never be violated:
analyzer.axon
Anchors are hard constraints. If violated, AXON’s self-healing runtime will retry with failure context. If max attempts are exceeded, it raises AnchorBreachError.

Step 6: Add Self-Healing with Refine

Make your program automatically retry and self-correct:
analyzer.axon
The 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:
This saves a trace to analyzer.trace.json. View it with:

Advanced Example: Contract Analyzer

Here’s a production-ready example from the AXON repository:
contract_analyzer.axon
This example demonstrates:

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:
Levels 1-3 trigger automatic self-healing via the RetryEngine. Level 4 means healing failed after max attempts.

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