Overview Provider-backed runnable examples generated from source headers. python examples examples src/examples/python example Overview

Examples

Every Python example here is runnable source under src/examples/python/ and calls a real provider API. The website and npm run example -- list are generated from each file’s ax-example header.

Groups

Generation

  • Python Typed Generation - Runs a small typed generation program against OpenAI. Run: npm run example -- python src/examples/python/generation/axgen-openai.py.
  • Python Structured Extraction - Extracts structured fields and labels from support text with OpenAI. Run: npm run example -- python src/examples/python/generation/structured.py.
  • Python Signature Constraints - Builds a constrained signature fluently and runs it with OpenAI. Run: npm run example -- python src/examples/python/generation/signature-constraints.py.
  • Centralized Usage Observer - Attributes every completed model call to a tenant, user, and request from one global observer. Run: npm run example -- python src/examples/python/generation/usage-observer.py.
  • Python Contextual Generation - Answers from supplied context and returns compact citations with OpenAI. Run: npm run example -- python src/examples/python/generation/context.py.
  • Python Adaptive Provider Balancing - Routes equivalent chat traffic using shared reliability, latency, and cost statistics. Run: npm run example -- python src/examples/python/generation/adaptive-balancer.py.

Agents

  • Python Grounded Support Agent - Answers a support question grounded in a handbook that is kept out of the model prompt via contextFields. Run: npm run example -- python src/examples/python/short-agents/agent-openai.py.
  • Python Incident Triage Agent - Triages a noisy incident report held in contextFields, using a lean contextPolicy to keep the raw log out of the prompt while it reasons. Run: npm run example -- python src/examples/python/short-agents/tools-agent.py.
  • Python Specialist Planner Agent - A specialist that plans a migration from a long brief held in contextFields, using a checkpointed contextPolicy and a runtime-output cap to stay compact. Run: npm run example -- python src/examples/python/short-agents/handoff-agent.py.
  • Python Multi-Model Panel - Fans one question across three providers (OpenAI, Gemini, Anthropic), then judges the candidates and synthesizes a single grounded answer. Run: npm run example -- python src/examples/python/short-agents/model-panel.py.

Long-Horizon Agents

  • Python Incident Log Forensics (RLM) - Infers service architecture and root-cause findings from a huge CloudWatch export that never enters the prompt – held in contextFields and worked through the runtime under a lean contextPolicy. Run: npm run example -- python src/examples/python/long-agents/incident-log-forensics.py.
  • Python Codebase Q&A with a Peek Context Map - Answers several dependency questions over one large module index by building and reusing an evolving context map (the “peek” orientation cache), so later questions skip re-scanning the corpus. Run: npm run example -- python src/examples/python/long-agents/codebase-peek-map.py.
  • Python Data Analyst (Large Context + Tools) - Combines a large data dictionary held in contextFields with typed warehouse tools, so the agent answers business questions over a big dataset it never has to inline. Run: npm run example -- python src/examples/python/long-agents/data-analyst-with-tools.py.
  • Python Self-Improving Lab Agent - A many-tool agent that runs experiments, grades them against a rubric with an independent verifier, and distills verified rules into memory – iterating until the rubric passes. Run: npm run example -- python src/examples/python/long-agents/self-improving-lab.py.
  • Python Skills + Memory Ops Assistant - An on-call assistant that recalls past decisions from a memory store and loads the right runbook skill on demand, using the agent skills and memories subsystems. Run: npm run example -- python src/examples/python/long-agents/skills-and-memory-assistant.py.
  • Python Smart Defaults Agent - Shows AxAgent smart defaults: oversized undeclared context stays out of the prompt while relevance hints and runtime tools guide the agent. Run: npm run example -- python src/examples/python/long-agents/smart-defaults-agent.py.

Flows

  • Python Sequential Flow - Runs a two-step Ax flow against OpenAI. Run: npm run example -- python src/examples/python/flows/flow-openai.py.
  • Python Branching Flow - Routes a classification through follow-up flow logic backed by OpenAI. Run: npm run example -- python src/examples/python/flows/branch-flow.py.
  • Python Parallel Flow - Runs two independent OpenAI-backed steps in parallel before joining their results. Run: npm run example -- python src/examples/python/flows/parallel-flow.py.
  • Python Composed Flow - Composes multiple typed programs into one OpenAI-backed flow. Run: npm run example -- python src/examples/python/flows/composed-flow.py.
  • Python Refinement Flow - Drafts, critiques, and revises an answer through three OpenAI-backed steps. Run: npm run example -- python src/examples/python/flows/refine-flow.py.

Audio

  • Python Text To Speech - Generates speech audio through OpenAI. Run: npm run example -- python src/examples/python/audio/speech-audio.py.
  • Python Speech To Text - Transcribes a checked-in WAV file through OpenAI. Run: npm run example -- python src/examples/python/audio/transcribe-audio.py.
  • Python Audio Summary Pipeline - Transcribes audio and summarizes the transcript with an OpenAI-backed generator. Run: npm run example -- python src/examples/python/audio/pipeline-audio.py.

MCP

  • Python Native MCP Tools - Attaches a live MCP client directly to AxGen without a lossy function adapter. Run: npm run example -- python src/examples/python/mcp/native-mcp-tools.py.
  • Python MCP Resource Wake - Subscribes over real Streamable HTTP and lets AxEventRuntime wake an authenticated Agent automatically. Run: npm run example -- python src/examples/python/mcp/resource-wake-agent.py.
  • Python MCP Task Continuation - Creates an owned continuation and resumes an AxFlow from real MCP progress and terminal task notifications. Run: npm run example -- python src/examples/python/mcp/task-resume-flow.py.

Optimization

  • Python AxGen Optimization - Runs a baseline OpenAI prediction and applies an optimizer artifact. Run: npm run example -- python src/examples/python/optimization/axgen-optimization.py.
  • Python GEPA Optimization - Pairs a real OpenAI baseline with a local GEPA optimization pass. Run: npm run example -- python src/examples/python/optimization/gepa-optimization.py.
  • Python Optimization Artifact Reuse - Saves and reapplies an optimizer artifact after a real OpenAI baseline. Run: npm run example -- python src/examples/python/optimization/artifact-optimization.py.
  • Python Agent Playbook — Learn And Verify - Attach a persistent playbook, add validated hidden citations and stage guidance, then mine a task set into playbook rules with a verification gate. Run: npm run example -- python src/examples/python/optimization/agent-playbook-evolve.py.

Source

  • Catalog: npm run example -- list --json from scripts/example-catalog.mjs
  • Files: src/examples/python/

Pages

  • Generation Generation — Python examples backed by real provider calls.
  • Agents Agents — Python examples backed by real provider calls.
  • Long-Horizon Agents Long-Horizon Agents — Python examples backed by real provider calls.
  • Flows Flows — Python examples backed by real provider calls.
  • Audio Audio — Python examples backed by real provider calls.
  • MCP MCP — Python examples backed by real provider calls.
  • Optimization Optimization — Python examples backed by real provider calls.
Docs