This directory contains examples demonstrating the capabilities of the Ax framework.
The main example demonstrates using a large teacher model (Gemini Pro) to optimize a small student model (SmolLM:360m) for complex algorithm implementation tasks.
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.tsPrerequisites: OpenAI API key (OPENAI_APIKEY environment variable)
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.tsPrerequisites: OpenAI API key (OPENAI_APIKEY environment variable)
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.tsWhat to look for:
- Variables are rendered with structured metadata like type and size.
- Durable runtime values such as
rows,bestRow, andsummaryappear as compact state lines in the second actor prompt. - This exercises the same structured collection path used by
Live Runtime Statein agent turns.
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.tsWhat to look for:
- The first
forward(...)throwsAxAgentClarificationErrorinstead 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.
-
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
-
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
- Ollama: Install from ollama.ai
- Docker & Docker Compose: For Python optimizer service
- Google AI API Key: Set
GOOGLE_APIKEYenvironment variable - Node.js 20+: For running the TypeScript example
- 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
The example will show:
- Initial poor performance of the small model on algorithm implementation
- MiPRO optimization process with progress updates (requires Python service)
- Significantly improved performance after optimization
- 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.
┌─────────────────┐ 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.
- 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
| 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 |
- No Objective Weighting: You don't need to decide upfront how to balance objectives
- Multiple Solutions: Get a range of optimal choices for different scenarios
- Trade-off Visibility: See exactly what you gain/lose when prioritizing one objective
- Robust Solutions: Pareto-optimal solutions are mathematically guaranteed to be optimal
- Future-Proof: As requirements change, you can select different points from the same frontier
- Ollama connection issues: Ensure Ollama is running on port 11434
- Python service issues: Check
docker-compose logsinsrc/optimizer/ - API key issues: Verify
GOOGLE_APIKEYis set correctly - Model download: SmolLM:360m download may take a few minutes on first run
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