Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Ax Framework Examples

This directory contains examples demonstrating the capabilities of the Ax framework.

Teacher-Student Optimization Example (MiPRO)

The main example demonstrates using a large teacher model (Gemini Pro) to optimize a small student model (SmolLM:360m) for complex algorithm implementation tasks.

Multi-Objective Optimization Example (GEPA)

A compelling demonstration of GEPA's unique multi-objective optimization capabilities, showing how it finds optimal trade-offs between conflicting objectives like quality vs speed in code review tasks.

Quick Start:

cd src/ax
npm run tsx src/examples/gepa-quality-vs-speed-optimization.ts

Prerequisites: OpenAI API key (OPENAI_APIKEY environment variable)

Agentic Context Engineering (ACE) Example

End-to-end walkthrough of the ACE optimizer that grows a structured playbook through generator → reflector → curator loops. The example trains offline on support ticket severities and then performs an online update after a new incident.

Quick Start:

cd src/ax
npm run tsx src/examples/ace-train-inference.ts

Prerequisites: OpenAI API key (OPENAI_APIKEY environment variable)

Live Runtime State Example

A small runnable example focused on the AxAgent runtime-state pipeline. It enables contextPolicy.state.summary and state.inspect, then runs a mock two-turn agent loop and prints the captured Live Runtime State block so you can verify the structured runtime-state formatting locally without needing an LLM API key.

Quick Start:

cd src/ax
npm run tsx src/examples/rlm-live-runtime-state.ts

What to look for:

  • Variables are rendered with structured metadata like type and size.
  • Durable runtime values such as rows, bestRow, and summary appear as compact state lines in the second actor prompt.
  • This exercises the same structured collection path used by Live Runtime State in agent turns.

Clarification Resume Example

A small runnable example focused on the new clarification-resume flow for AxAgent. It uses AxMockAIService, throws AxAgentClarificationError, saves the continuation artifact with error.getState(), restores it with agent.setState(...), and resumes the next forward(...) call from the prior runtime state without needing an LLM API key.

Quick Start:

cd src/ax
npm run tsx src/examples/rlm-clarification-resume.ts

What to look for:

  • The first forward(...) throws AxAgentClarificationError instead of going through the responder.
  • The saved state contains runtime bindings and prior action-log history.
  • The resumed call succeeds after setState(savedState) and reuses values created before the clarification.

Quick Start

  1. Automated Setup (Recommended):

    # Start all required services automatically
    ./scripts/start-teacher-student-demo.sh
    
    # In another terminal, run the example
    cd src/ax
    npm run tsx src/examples/teacher-student-optimization.ts
  2. Manual Setup:

    # Start Ollama
    ollama serve
    ollama pull smollm:360m
    
    # Start Python optimizer
    cd src/optimizer
    docker-compose up -d
    
    # Run example
    cd ../ax
    npm run tsx src/examples/teacher-student-optimization.ts

Prerequisites

  • Ollama: Install from ollama.ai
  • Docker & Docker Compose: For Python optimizer service
  • Google AI API Key: Set GOOGLE_APIKEY environment variable
  • Node.js 20+: For running the TypeScript example

What the Example Demonstrates

  • Teacher-Student Learning: Large model (Gemini Pro) guides optimization of small model (SmolLM:360m)
  • Complex Task: Algorithm implementation requiring understanding of data structures, edge cases, and Python syntax
  • MiPRO Optimization: Uses the MiPRO optimizer with Python backend for advanced optimization algorithms
  • Before/After Comparison: Shows improvement in the small model's capabilities
  • Real-world Scenario: Demonstrates how to make small models perform complex tasks they initially can't handle

Expected Output

The example will show:

  1. Initial poor performance of the small model on algorithm implementation
  2. MiPRO optimization process with progress updates (requires Python service)
  3. Significantly improved performance after optimization
  4. Concrete examples of generated algorithm implementations

Note: The example requires the Python optimizer service to be running. Without it, the optimization will fail with a clear error message.

Architecture

┌─────────────────┐    guides    ┌─────────────────┐
│   Gemini Pro    │─────────────▶│   MiPRO         │
│  (Teacher)      │              │  Optimizer      │
└─────────────────┘              └─────────────────┘
                                           │
                                           ▼
┌─────────────────┐    optimizes  ┌─────────────────┐
│ Python Service  │◀──────────────│  SmolLM:360m    │
│ (Optuna/TPE)    │               │  (Student)      │
└─────────────────┘               └─────────────────┘

The teacher model provides high-quality examples and guidance, while the Python optimizer service uses advanced algorithms (TPE, Bayesian optimization) to find the best prompts and configurations to improve the student model's performance.

What the GEPA Example Demonstrates

  • Multi-Objective Optimization: Simultaneously optimizes for quality (thoroughness) and speed (conciseness)
  • Pareto Frontier Discovery: Finds multiple optimal solutions instead of just one "best" solution
  • Trade-off Analysis: Shows the inherent tension between conflicting objectives
  • Real-world Application: Code review task where you might want different trade-offs for different scenarios
  • Hypervolume Metrics: Quantifies improvement across the entire objective space
  • Solution Selection: Choose the optimal point based on your specific requirements

GEPA vs MiPRO Comparison

Aspect MiPRO GEPA
Objectives Single (composite score) Multiple (Pareto frontier)
Output One "best" solution Set of optimal trade-offs
Use Case Clear single goal Conflicting objectives
Optimization Teacher-student + Python backend Reflective evolution
Selection Automatic best User chooses from frontier

GEPA Advantages

  1. No Objective Weighting: You don't need to decide upfront how to balance objectives
  2. Multiple Solutions: Get a range of optimal choices for different scenarios
  3. Trade-off Visibility: See exactly what you gain/lose when prioritizing one objective
  4. Robust Solutions: Pareto-optimal solutions are mathematically guaranteed to be optimal
  5. Future-Proof: As requirements change, you can select different points from the same frontier

Troubleshooting

  • Ollama connection issues: Ensure Ollama is running on port 11434
  • Python service issues: Check docker-compose logs in src/optimizer/
  • API key issues: Verify GOOGLE_APIKEY is set correctly
  • Model download: SmolLM:360m download may take a few minutes on first run

Customization

You can modify the example to:

  • Use different teacher/student model pairs
  • Try different complex tasks (code generation, reasoning, creative writing)
  • Adjust MiPRO optimization parameters
  • Experiment with different evaluation metrics
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.