Examples
Every Rust example here is runnable source under src/examples/rust/ and calls a real provider API. The website and npm run example -- list are generated from each file’s ax-example header.
Groups
- Generation - 32 examples.
- Agents - 7 examples.
- Long-Horizon Agents - 6 examples.
- Flows - 7 examples.
- Audio - 3 examples.
- MCP - 3 examples.
- Optimization - 4 examples.
Generation
- Rust Prompt-Cached Generation - Runs GPT-6 structured generation with stable OpenAI prompt-cache affinity. Run:
npm run example -- rust src/examples/rust/generation/basic_generation.rs. - Rust Astra Generation - Runs Astra through the standard generator with automatic Responses routing and prompt caching. Run:
npm run example -- rust src/examples/rust/generation/astra.rs. - Rust GPT-6.1 Sol Generation - Runs GPT-6.1 Sol through the standard generator with automatic Responses routing and prompt caching. Run:
npm run example -- rust src/examples/rust/generation/gpt61_sol.rs. - Rust Model Catalog - Lists static models and named OpenAI-compatible profiles with portable thinking levels and service tiers. Run:
npm run example -- rust src/examples/rust/generation/model_catalog.rs. - Rust Jev Signature Decisions - Converts Jev probabilities into boolean and class outputs with a provider threshold. Run:
npm run example -- rust src/examples/rust/generation/typesafe.rs. - Rust OpenAI Signature Decisions - Converts OpenAI probabilities into boolean and class outputs with a provider threshold. Run:
npm run example -- rust src/examples/rust/generation/openai-decisions.rs. - Rust Meta Muse Spark - Selects any of Meta’s three protocols through the existing chat API. Run:
npm run example -- rust src/examples/rust/generation/meta_muse.rs. - Rust Structured Extraction - Extracts structured fields and labels from support text with OpenAI. Run:
npm run example -- rust src/examples/rust/generation/structured_generation.rs. - Rust Vertex Gemini Routing - Calls Gemini through Vertex with project and multi-region routing. Run:
npm run example -- rust src/examples/rust/generation/vertex_gemini.rs. - Rust Jev Hybrid Reply - Passes Jev decisions to a second Ax program to generate a customer reply. Run:
npm run example -- rust src/examples/rust/generation/typesafe-hybrid.rs. - Rust Signature Constraints - Builds native constrained fields and runs the signature with OpenAI. Run:
npm run example -- rust src/examples/rust/generation/signature-constraints.rs. - Centralized Usage Observer - Attributes every completed model call to a tenant, user, and request from one global observer. Run:
npm run example -- rust src/examples/rust/generation/usage_observer.rs. - Rust Incremental Provider Stream - Iterates OpenAI SSE events incrementally; dropping the iterator closes the response. Run:
npm run example -- rust src/examples/rust/generation/provider_stream.rs. - Rust Decision Evidence Reranking - Ranks documents through Ax signatures while retaining decision evidence and candidate IDs. Run:
npm run example -- rust src/examples/rust/generation/decision-evidence.rs. - Rust Portable Cancellation - Cancels a provider request before transport and preserves the first cancellation reason. Run:
npm run example -- rust src/examples/rust/generation/cancellation.rs. - Rust Sonnet 5.5 Between-Tool Thinking - Disables pre-response thinking while retaining signed updates for replay. Run:
npm run example -- rust src/examples/rust/generation/sonnet55_between_tools.rs. - Rust Streaming Field Deltas - Streams AxGen output as TypeScript-style {version, index, delta} field deltas and merges them as they arrive. Run:
npm run example -- rust src/examples/rust/generation/streaming_forward.rs. - Rust Date Fields - Parses date, datetime and range outputs into ISO 8601 by default as TypeScript does; named zones read the platform tz database. Run:
npm run example -- rust src/examples/rust/generation/date_fields.rs. - Rust Field Processor Feedback - Sends a field processor’s note back to the model for another step, as TypeScript does, and trims the final answer with a field transform. Run:
npm run example -- rust src/examples/rust/generation/field_processors.rs. - Rust Haiku 5.5 Adaptive Thinking - Uses Haiku 5.5 adaptive thinking at low effort for a short response. Run:
npm run example -- rust src/examples/rust/generation/haiku55.rs. - Rust Tool Result Formatting - Formats a structured inventory tool result as concise text for the model. Run:
npm run example -- rust src/examples/rust/generation/function_result_formatter.rs. - Rust Forward Cache - Reuses a typed generation result through a caching callback on forward options. Run:
npm run example -- rust src/examples/rust/generation/forward_cache.rs. - Rust Gemini Flex Inference - Sends latency-tolerant work through Gemini Flex and reports the applied tier. Run:
npm run example -- rust src/examples/rust/generation/gemini_service_tier.rs. - Rust Native File Routing - Summarizes a PDF through a provider router without replacing the native file with extracted text. Run:
npm run example -- rust src/examples/rust/generation/native_file_routing.rs. - Rust Automatic Background Tools - Uses ordinary generation with background tools, steering, and a reasoning update. Run:
npm run example -- rust src/examples/rust/generation/astra_async.rs. - Rust Cancel Background Work - Cancels a live Astra run through the high-level controller and observes cooperative tool cancellation. Run:
npm run example -- rust src/examples/rust/generation/astra_cancellation.rs. - Rust Native Astra Steering - Steers a running generation through the high-level controller using the optional WebSocket transport. Run:
npm run example -- rust src/examples/rust/generation/astra_native_steering.rs. - Rust Contextual Generation - Answers from supplied context and returns compact citations with OpenAI. Run:
npm run example -- rust src/examples/rust/generation/context_generation.rs. - Rust Jev Native Questions - Uses structured criteria, native scoring, model discovery, and probability-based decisions. Run:
npm run example -- rust src/examples/rust/generation/typesafe-native.rs. - Rust Adaptive Provider Balancing - Routes equivalent chat traffic using shared reliability, latency, and cost statistics. Run:
npm run example -- rust src/examples/rust/generation/adaptive_balancer.rs. - Rust OpenAI Native Decisions - Uses ordered predicate, choice, and score questions with explicit rubrics and raw probabilities. Run:
npm run example -- rust src/examples/rust/generation/openai-decisions-native.rs. - Portable Runtime Hooks - Applies global and forward-scoped rate limiting, tracing, and metrics to AxGen, AxAgent, and AxFlow. Run:
npm run example -- rust src/examples/rust/generation/runtime_hooks.rs.
Agents
- Rust 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 -- rust src/examples/rust/short-agents/basic_agent.rs. - Rust Streaming Agent - Streams an agent’s answer as field deltas while its evidence citations are checked against what the agent read from a handbook kept out of the prompt. Run:
npm run example -- rust src/examples/rust/short-agents/streaming_agent.rs. - Rust 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 -- rust src/examples/rust/short-agents/tools_agent.rs. - Rust Agent Background Tools - Runs declared background agent tools with steering and verifies final result incorporation. Run:
npm run example -- rust src/examples/rust/short-agents/astra_async_agent.rs. - Rust Child Agent Controls - Delegates through a real actor runtime and applies controls to the child scope. Run:
npm run example -- rust src/examples/rust/short-agents/astra_child_agent.rs. - Rust 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 -- rust src/examples/rust/short-agents/handoff_agent.rs. - Rust 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 -- rust src/examples/rust/short-agents/model_panel.rs.
Long-Horizon Agents
- Rust 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 -- rust src/examples/rust/long-agents/incident_log_forensics.rs. - Rust 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 -- rust src/examples/rust/long-agents/codebase_peek_map.rs. - Rust 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 -- rust src/examples/rust/long-agents/data_analyst_with_tools.rs. - Rust 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 -- rust src/examples/rust/long-agents/self_improving_lab.rs. - Rust 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 -- rust src/examples/rust/long-agents/skills_and_memory_assistant.rs. - Rust 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 -- rust src/examples/rust/long-agents/smart_defaults_agent.rs.
Flows
- Rust Sequential Flow - Runs a two-step Ax flow against OpenAI. Run:
npm run example -- rust src/examples/rust/flows/sequential_flow.rs. - Rust Branching Flow - Routes a classification through follow-up flow logic backed by OpenAI. Run:
npm run example -- rust src/examples/rust/flows/branch_flow.rs. - Rust Parallel Flow - Runs two independent OpenAI-backed steps in parallel before joining their results. Run:
npm run example -- rust src/examples/rust/flows/parallel-flow.rs. - Rust Controlled Background Flow - Uses ordinary generation with background tools, steering, and a reasoning update. Run:
npm run example -- rust src/examples/rust/flows/astra_async.rs. - Rust Concurrent Astra Flow - Independent conversations overlap, retain their tool results, and receive scoped controls. Run:
npm run example -- rust src/examples/rust/flows/astra_parallel.rs. - Rust Composed Flow - Composes multiple typed programs into one OpenAI-backed flow. Run:
npm run example -- rust src/examples/rust/flows/composed_flow.rs. - Rust Refinement Flow - Drafts, critiques, and revises an answer through three OpenAI-backed steps. Run:
npm run example -- rust src/examples/rust/flows/refine-flow.rs.
Audio
- Rust Text To Speech - Generates speech audio through OpenAI. Run:
npm run example -- rust src/examples/rust/audio/speech_audio.rs. - Rust Speech To Text - Transcribes a checked-in WAV file through OpenAI. Run:
npm run example -- rust src/examples/rust/audio/transcribe_audio.rs. - Rust Audio Summary Pipeline - Transcribes audio and summarizes the transcript with an OpenAI-backed generator. Run:
npm run example -- rust src/examples/rust/audio/pipeline_audio.rs.
MCP
- Rust Native MCP Tools - Attaches a live MCP client directly to AxGen without a lossy function adapter. Run:
npm run example -- rust src/examples/rust/mcp/native_mcp_tools.rs. - Rust MCP Resource Wake - Subscribes over real Streamable HTTP and lets AxEventRuntime wake an authenticated Agent automatically. Run:
npm run example -- rust src/examples/rust/mcp/resource_wake_agent.rs. - Rust MCP Task Continuation - Creates an owned continuation and resumes an AxFlow from real MCP progress and terminal task notifications. Run:
npm run example -- rust src/examples/rust/mcp/task_resume_flow.rs.
Optimization
- Rust AxGen Optimization - Runs a baseline OpenAI prediction and applies an optimizer artifact. Run:
npm run example -- rust src/examples/rust/optimization/axgen_optimization.rs. - Rust GEPA Optimization - Pairs a real OpenAI baseline with a local GEPA optimization pass. Run:
npm run example -- rust src/examples/rust/optimization/gepa_optimization.rs. - Rust Optimization Artifact Reuse - Saves and reapplies an optimizer artifact after a real OpenAI baseline. Run:
npm run example -- rust src/examples/rust/optimization/artifact_optimization.rs. - Rust 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 -- rust src/examples/rust/optimization/agent_playbook_evolve.rs.
Source
- Catalog:
npm run example -- list --jsonfromscripts/example-catalog.mjs - Files:
src/examples/rust/
Pages
- Generation Generation — Rust examples backed by real provider calls.
- Agents Agents — Rust examples backed by real provider calls.
- Long-Horizon Agents Long-Horizon Agents — Rust examples backed by real provider calls.
- Flows Flows — Rust examples backed by real provider calls.
- Audio Audio — Rust examples backed by real provider calls.
- MCP MCP — Rust examples backed by real provider calls.
- Optimization Optimization — Rust examples backed by real provider calls.