ax-llm/ax
The pretty much "official" DSPy framework for Typescript
Ax – A Multi‑language Framework for Structured LLM Apps
What it is – Ax (pronounced “ax‑llm”) is a library that lets you describe typed interactions with large language models (LLMs) once and run the same code in many languages: TypeScript/JavaScript, Python, Java, C++, Go, and Rust. It provides a small DSL for declaring signatures (input‑output schemas), then compiles that description into language‑specific client libraries that talk to any supported provider (OpenAI, Anthropic, Gemini, etc.).
Key concepts
- Signatures – Declare the shape of a request/response using a string DSL, a fluent
f()builder, or any Standard Schema v1 validator (Zod, Valibot, ArkType). The framework parses the model’s output and validates it, giving you a guaranteed‑type result. - Deployment profiles – Named profiles (e.g.,
openai,together,deepseek) encapsulate provider‑specific endpoints and wiring. Switching providers is a one‑line change. - Agents – Long‑running, tool‑using actors with memory, checkpointed context, and sandboxed JavaScript execution. Agents run a three‑stage pipeline: distiller → executor (RLM loop) → responder.
- Flows – Typed, directed‑acyclic graphs of LLM‑driven nodes. Nodes can branch, loop, run in parallel, and the framework automatically optimizes independent nodes.
- Optimizers – Built‑in support for few‑shot bootstrapping, GEPA, and reusable optimizer artifacts.
- Cross‑language core – The same Ax IR is compiled to native packages for each target language. The source TypeScript package (
@ax-llm/ax) is the canonical implementation; generated Python (axllm), Java (dev.axllm:ax), C++ (axllm::axllm), Go, and Rust crates are checked into the repo.
How you use it (TypeScript example)
import { ai, ax } from "@ax-llm/ax";
const llm = ai({ name: "openai", apiKey: process.env.OPENAI_APIKEY });
const classify = ax(
'review:string -> sentiment:class "positive, negative, neutral"'
);
const { sentiment } = await classify.forward(llm, {
review: "This product is amazing!"
}); // sentiment is typed as "positive" | "negative" | "neutral"
The same signature can be run in Python, Java, etc. with identical semantics.
Features that matter
- Zero prompt engineering – The DSL generates the prompt automatically.
- Streaming by default – Results are parsed as they arrive, allowing early validation and cancellation.
- Typed multimodal I/O – Supports
image,audio,filefields alongside text. - Tool (ReAct) integration – Declare functions that the model can call.
- Sandboxed JS runtime – Agents execute generated JavaScript in a hardened environment with fine‑grained permissions.
- Memory & skills – Agents can query vector stores or skill libraries during a run.
- Performance‑aware – The hot path is a thin wrapper around the provider SDK; benchmarks show latency close to raw calls.
Getting started
- Install the TypeScript package via npm (
npm i @ax-llm/ax). - Run the bundled examples with
npm run example -- <language> <path>(e.g.,npm run example -- python src/examples/python/generation/axgen-openai.py). - For other languages, add the published package (
pip install axllm, Maven Central, crates.io, etc.) and import the same symbols (ai,ax,agent,flow).
Who it’s for
- Developers building production LLM services who want type safety across languages.
- Teams that need a single source of truth for model contracts and want to switch providers without code changes.
- Projects that require agents with memory, tool use, and sandboxed execution.
Links
- npm: https://www.npmjs.com/package/@ax-llm/ax
- PyPI: https://pypi.org/project/axllm/
- crates.io: https://crates.io/crates/axllm
- Maven Central: https://central.sonatype.com/artifact/dev.axllm/ax
- Discord community: https://discord.gg/DSHg3dU7dW
All details above are taken directly from the repository’s README.
Related
- Project
- Project
- Project
- Project
- Project