@ax-llm/ax

中文文档
25.4.9发布于 2026/11/07Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 21.4万

The best library to work with LLMs

原始使用文档
文档目录25 节
  1. Transform Your AI Development in 30 Seconds
  2. Decision Evidence and Reranking
  3. Why Thousands of Developers Choose Ax
  4. 🎯 Define Once, Run Anywhere
  5. ⚡ Ship 10x Faster
  6. ⚡ Provider-Native Speed
  7. 🛡️ Production-Ready from Day One
  8. 🚀 Gets Smarter Over Time
  9. Real Apps, Real Simple
  10. Extract Structured Data from Customer Emails
  11. Build Agents That Use Tools (ReAct Pattern)
  12. Multi-Modal Analysis with Images
  13. Quick Start
  14. Install
  15. Your First AI Feature (2 minutes)
  16. Powerful Features, Zero Complexity
  17. Learn More
  18. 🚀 Quick Wins
  19. 📚 Deep Dives
  20. Examples
  21. Core Examples
  22. Production Patterns
  23. Join the Community
  24. Production Ready
  25. License

Ax: Build Reliable AI Apps in TypeScript

Stop wrestling with prompts. Start shipping AI features.

Ax brings DSPy's revolutionary approach to TypeScript – just describe what you want, and let the framework handle the rest. Production-ready, type-safe, and works with all major LLMs.

NPM Package Twitter Discord Chat

Transform Your AI Development in 30 Seconds

import { ai, ax } from "@ax-llm/ax";

// 1. Pick any LLM
const llm = ai({ name: "openai", apiKey: process.env.OPENAI_APIKEY! });

// 2. Say what you want
const classifier = ax(
  'review:string -> sentiment:class "positive, negative, neutral"',
);

// 3. Get type-safe results
const result = await classifier.forward(llm, {
  review: "This product is amazing!",
});
console.log(result.sentiment); // "positive" ✨

That's it. No prompt engineering. No trial and error. It works with GPT-4, Claude, Gemini, or any LLM.

Decision Evidence and Reranking

Use Jev or OpenAI Decisions through normal Ax signatures and AxGen. Add (evidence) or fluent .withEvidence() to boolean/class fields, and declare ordered rubric scores with score. Native probabilities, selected values, continuous scores, and optional confidence stay in the result; Ax attaches provider/model provenance. Generative models use the same signature with estimates marked elicited, without native confidence. Shared result shapes do not imply comparable confidence calibration across models.

const judge = ax(
  'query:string, document:string -> relevant:boolean(evidence, threshold 0.7), relevance:score "Irrelevant, Related, Partial answer, Direct answer"(evidence)',
);
const decisions = ai({ name: 'openai-decisions', apiKey: process.env.OPENAI_APIKEY! });
const result = await judge.forward(decisions, {
  query: 'How do I request a refund?',
  document: 'Request a refund through your account billing page.',
});
console.log(result.relevance.value, result.relevant.probability);

For reranking, keep candidate IDs in application code and sort results by relevance.value. See signatures and decision evidence for thresholds, result shapes, and refusal handling.

Why Thousands of Developers Choose Ax

🎯 Define Once, Run Anywhere

Write your logic once. Switch between OpenAI, Anthropic, Google, or 15+ providers with one line. No rewrites needed.

⚡ Ship 10x Faster

Stop tweaking prompts. Define inputs → outputs. The framework generates optimal prompts automatically.

⚡ Provider-Native Speed

Ax stays in the same latency class as direct provider calls while adding typed outputs, validation, retries, tracing, and tools. Streaming is the default so Ax can parse fields as they arrive, fail early on streaming assertions, cancel bad outputs, and start correction without wasting tokens on completions that are already invalid.

Benchmark the current code against your own providers:

AX_STREAM_BENCH_PROVIDER=anthropic AX_STREAM_BENCH_MODEL=claude-sonnet-4-5-20250929 AX_STREAM_BENCH_RUNS=2 AX_STREAM_BENCH_WARMUP_RUNS=0 npm run tsx src/examples/streaming-latency.ts
AX_STREAM_BENCH_PROVIDER=google-gemini AX_STREAM_BENCH_MODEL=gemini-3.5-flash AX_STREAM_BENCH_RUNS=2 AX_STREAM_BENCH_WARMUP_RUNS=0 npm run tsx src/examples/streaming-latency.ts

🛡️ Production-Ready from Day One

Built-in streaming, validation, error handling, observability. Used by startups in production handling millions of requests.

🚀 Gets Smarter Over Time

Train your programs with examples. Watch accuracy improve automatically. No ML expertise needed.

Real Apps, Real Simple

Extract Structured Data from Customer Emails

const extractor = ax(`
  customerEmail:string, currentDate:datetime -> 
  priority:class "high, normal, low",
  sentiment:class "positive, negative, neutral",
  ticketNumber?:number,
  nextSteps:string[],
  estimatedResponseTime:string
`);

const result = await extractor.forward(ai, {
  customerEmail: "Order #12345 hasn't arrived. Need this resolved immediately!",
  currentDate: new Date(),
});
// Automatically extracts all fields with proper types and validation

Build Agents That Use Tools (ReAct Pattern)

const assistant = ax(
  "question:string -> answer:string",
  {
    functions: [
      { name: "getCurrentWeather", func: weatherAPI },
      { name: "searchNews", func: newsAPI },
    ],
  },
);

const result = await assistant.forward(ai, {
  question: "What's the weather in Tokyo and any news about it?",
});
// AI automatically calls both functions and combines results

Multi-Modal Analysis with Images

const analyzer = ax(`
  image:image, question:string ->
  description:string,
  mainColors:string[],
  category:class "electronics, clothing, food, other",
  estimatedPrice:string
`);
// Process images and text together seamlessly

Quick Start

Install

npm install @ax-llm/ax

Outside CI, installation sets up one Claude Code skill, ax-llm, with a compact index and bundled guides your agent reads as needed. To disable future automatic setup, run npx @ax-llm/ax skills-auto-install off from your project root. This saves ax.skills.autoInstall: false in your project's package.json; commit that setting to share it with your team. Use skills-auto-install on to re-enable automatic setup on future installs. Set AX_SKIP_SKILL_INSTALL=1 to skip setup for a single installation; CI and this environment variable take precedence over the saved setting.

You can also set the preference before installing Ax for the first time:

{
  "ax": {
    "skills": {
      "autoInstall": false
    }
  }
}

Merge this field into your existing package.json. Manual npx @ax-llm/ax setup-claude works even when automatic setup is disabled; add --all to register every specialist or --skill ax-ai to install only one. Changing the preference leaves installed skills in place, and manual setup or removal preserves the saved preference. Existing specialists remain installed; use remove-claude followed by setup-claude to switch an older full installation to the compact bundle.

Your First AI Feature (2 minutes)

import { ai, ax } from "@ax-llm/ax";

const llm = ai({ name: "openai", apiKey: process.env.OPENAI_APIKEY! });

const translator = ax(`
  text:string, 
  language:string -> 
  translation:string
`);

const result = await translator.forward(llm, {
  text: "Hello world",
  language: "Spanish",
});
console.log(result.translation); // "Hola mundo"

Powerful Features, Zero Complexity

  • ✅ Model-Lab Providers - OpenAI, Anthropic, Google, Mistral, DeepSeek, Grok/xAI, and more
  • ✅ Type-Safe Everything - Full TypeScript support with auto-completion
  • ✅ Streaming First - Real-time responses with validation
  • ✅ Multi-Modal - Images, audio, text in the same signature
  • ✅ Smart Optimization - Automatic prompt tuning with GEPA and bootstrap demos
  • ✅ Production Observability - OpenTelemetry tracing built-in
  • ✅ Advanced Workflows - Compose complex pipelines with AxFlow
  • ✅ Agent Framework - Agents that can use tools and call other agents
  • ✅ Zero Dependencies - Lightweight, fast, reliable

Learn More

🚀 Quick Wins

📚 Deep Dives

Examples

Run any example:

OPENAI_APIKEY=your-key npm run tsx ./src/examples/[example-name].ts

Core Examples

Production Patterns

📚 View Full Examples Guide →
View All 70+ Examples →

Join the Community

Production Ready

  • ✅ Battle-tested - Used by startups in production
  • ✅ No breaking changes - Stable minor versions
  • ✅ Comprehensive tests - Large test coverage
  • ✅ OpenTelemetry - Built-in observability
  • ✅ TypeScript first - Type-safe by design

License

Apache 2 - Use it anywhere, build anything.


Ready to build the future? Stop fighting with prompts. Start shipping with signatures.

npm install @ax-llm/ax

Built with ❤️ by developers, for developers.

版本与发布记录

@ax-llm/ax 共发布 457 个版本,首次发布于 2024/06/16;过去 12 个月发布了 217 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
25.4.9latest2026/11/071 天前
25.4.82026/11/034 天前
25.4.72026/10/299 天前
25.4.62026/10/2612 天前
25.4.52026/10/2117 天前
25.4.42026/10/2118 天前

关于 @ax-llm/ax 的常见问题

@ax-llm/ax 是什么?

The best library to work with LLMs

如何安装 @ax-llm/ax?

在项目目录运行 npm install @ax-llm/ax,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ax,可以用 npx ax 直接运行。

@ax-llm/ax 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ax-llm/ax 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ax-llm/ax 可以商用吗?

@ax-llm/ax 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ax-llm/ax 的下载量有多少?

根据 npm 官方下载统计,@ax-llm/ax 在 2026/10/08 – 2026/11/06 这 30 天内被下载 213,589 次,日均约 7,120 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ax-llm/ax 还在维护吗?

最新版本 25.4.9 发布于 2026/11/07(1 天前);至今共发布 457 个版本,其中过去 12 个月发布了 217 个;首次发布于 2024/06/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。