{"id":13494648,"url":"https://github.com/ax-llm/ax","last_synced_at":"2026-04-02T00:45:35.949Z","repository":{"id":78712339,"uuid":"605728251","full_name":"ax-llm/ax","owner":"ax-llm","description":"The pretty much \"official\" DSPy framework for Typescript","archived":false,"fork":false,"pushed_at":"2026-02-25T02:49:52.000Z","size":25124,"stargazers_count":2434,"open_issues_count":29,"forks_count":155,"subscribers_count":18,"default_branch":"main","last_synced_at":"2026-02-25T07:55:03.415Z","etag":null,"topics":["ai","anthropic","claude","cohere","dspy","gemini","google","google-gemini","gpt-4","javascript","large-language-models","llm","nodejs","ollama","openai","opensource","rag","typescript","vectordb","webllm"],"latest_commit_sha":null,"homepage":"http://axllm.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ax-llm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2023-02-23T19:21:40.000Z","updated_at":"2026-02-25T02:49:55.000Z","dependencies_parsed_at":"2023-09-22T02:24:13.965Z","dependency_job_id":"b55e12e2-8887-4475-971b-f83660793bdd","html_url":"https://github.com/ax-llm/ax","commit_stats":{"total_commits":465,"total_committers":10,"mean_commits":46.5,"dds":"0.058064516129032295","last_synced_commit":"0df54c16441ffe89ef3f693f8654a40f682fbfcf"},"previous_names":["dosco/llm-client","dosco/minds","ax-llm/ax","dosco/ax"],"tags_count":365,"template":false,"template_full_name":null,"purl":"pkg:github/ax-llm/ax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ax-llm%2Fax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ax-llm%2Fax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ax-llm%2Fax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ax-llm%2Fax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ax-llm","download_url":"https://codeload.github.com/ax-llm/ax/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ax-llm%2Fax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29966684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T09:33:09.965Z","status":"ssl_error","status_checked_at":"2026-03-01T09:25:48.915Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","anthropic","claude","cohere","dspy","gemini","google","google-gemini","gpt-4","javascript","large-language-models","llm","nodejs","ollama","openai","opensource","rag","typescript","vectordb","webllm"],"created_at":"2024-07-31T19:01:26.839Z","updated_at":"2026-04-02T00:45:35.942Z","avatar_url":"https://github.com/ax-llm.png","language":"TypeScript","readme":"# Ax - Build Reliable AI Apps in TypeScript with DSPy\n\nAx brings DSPy's approach to TypeScript – describe what you want, and let the framework handle the rest. Production-ready, type-safe, works with all major LLMs.\n\n[![NPM Package](https://img.shields.io/npm/v/@ax-llm/ax?style=for-the-badge\u0026color=green)](https://www.npmjs.com/package/@ax-llm/ax)\n[![Twitter](https://img.shields.io/twitter/follow/dosco?style=for-the-badge\u0026color=red)](https://twitter.com/dosco)\n[![Discord Chat](https://img.shields.io/discord/1078454354849304667?style=for-the-badge\u0026color=green)](https://discord.gg/DSHg3dU7dW)\n\n## The Problem\n\nBuilding with LLMs is painful. You write prompts, test them, they break. You switch providers, everything needs rewriting. You add validation, error handling, retries – suddenly you're maintaining infrastructure instead of shipping features.\n\n## The Solution\n\nDefine what goes in and what comes out. Ax handles the rest.\n\n```typescript\nimport { ai, ax } from \"@ax-llm/ax\";\n\nconst llm = ai({ name: \"openai\", apiKey: process.env.OPENAI_APIKEY });\n\nconst classifier = ax(\n  'review:string -\u003e sentiment:class \"positive, negative, neutral\"',\n);\n\nconst result = await classifier.forward(llm, {\n  review: \"This product is amazing!\",\n});\n\nconsole.log(result.sentiment); // \"positive\"\n```\n\nNo prompt engineering. No trial and error. Works with GPT-4, Claude, Gemini, or any LLM.\n\n## Why Ax\n\n**Write once, run anywhere.** Switch between OpenAI, Anthropic, Google, or 15+ providers with one line. No rewrites.\n\n**Ship faster.** Stop tweaking prompts. Define inputs and outputs. The framework generates optimal prompts automatically.\n\n**Production-ready.** Built-in streaming, validation, error handling, observability. Used in production handling millions of requests.\n\n**Gets smarter.** Train your programs with examples. Watch accuracy improve automatically. No ML expertise needed.\n\n## Examples\n\n### Extract structured data\n\n```typescript\nconst extractor = ax(`\n  customerEmail:string, currentDate:datetime -\u003e \n  priority:class \"high, normal, low\",\n  sentiment:class \"positive, negative, neutral\",\n  ticketNumber?:number,\n  nextSteps:string[],\n  estimatedResponseTime:string\n`);\n\nconst result = await extractor.forward(llm, {\n  customerEmail: \"Order #12345 hasn't arrived. Need this resolved immediately!\",\n  currentDate: new Date(),\n});\n```\n\n### Complex nested objects\n\n```typescript\nimport { f, ax } from \"@ax-llm/ax\";\n\nconst productExtractor = f()\n  .input(\"productPage\", f.string())\n  .output(\"product\", f.object({\n    name: f.string(),\n    price: f.number(),\n    specs: f.object({\n      dimensions: f.object({\n        width: f.number(),\n        height: f.number()\n      }),\n      materials: f.array(f.string())\n    }),\n    reviews: f.array(f.object({\n      rating: f.number(),\n      comment: f.string()\n    }))\n  }))\n  .build();\n\nconst generator = ax(productExtractor);\nconst result = await generator.forward(llm, { productPage: \"...\" });\n\n// Full TypeScript inference\nconsole.log(result.product.specs.dimensions.width);\nconsole.log(result.product.reviews[0].comment);\n```\n\n### Validation and constraints\n\n```typescript\nconst userRegistration = f()\n  .input(\"userData\", f.string())\n  .output(\"user\", f.object({\n    username: f.string().min(3).max(20),\n    email: f.string().email(),\n    age: f.number().min(18).max(120),\n    password: f.string().min(8).regex(\"^(?=.*[A-Za-z])(?=.*\\\\d)\", \"Must contain letter and digit\"),\n    bio: f.string().max(500).optional(),\n    website: f.string().url().optional(),\n  }))\n  .build();\n```\n\nAvailable constraints: `.min(n)`, `.max(n)`, `.email()`, `.url()`, `.date()`, `.datetime()`, `.regex(pattern, description)`, `.optional()`\n\nValidation runs on both input and output. Automatic retry with corrections on validation errors.\n\n### Agents with tools (ReAct pattern)\n\n```typescript\nconst assistant = ax(\n  \"question:string -\u003e answer:string\",\n  {\n    functions: [\n      { name: \"getCurrentWeather\", func: weatherAPI },\n      { name: \"searchNews\", func: newsAPI },\n    ],\n  },\n);\n\nconst result = await assistant.forward(llm, {\n  question: \"What's the weather in Tokyo and any news about it?\",\n});\n```\n\n### AxAgent + RLM for long context\n\n```typescript\nimport { agent, AxJSRuntime } from \"@ax-llm/ax\";\n\nconst analyzer = agent(\n  \"context:string, query:string -\u003e answer:string, evidence:string[]\",\n  {\n    name: \"documentAnalyzer\",\n    description: \"Analyze very long documents with recursive code + sub-queries\",\n    maxSteps: 20,\n    rlm: {\n      contextFields: [\"context\"],\n      runtime: new AxJSRuntime(),\n      maxSubAgentCalls: 40,\n      maxRuntimeChars: 2_000, // Shared cap for llmQuery context + interpreter output\n      maxBatchedLlmQueryConcurrency: 6,\n      subModel: \"gpt-4o-mini\",\n    },\n  },\n);\n\nconst result = await analyzer.forward(llm, {\n  context: veryLongDocument,\n  query: \"What are the main arguments and supporting evidence?\",\n});\n```\n\nRLM mode keeps long context out of the root prompt, runs iterative analysis in a persistent runtime session, and uses bounded sub-queries for semantic extraction (typically targeting \u003c=10k chars per sub-call).\n\n### AxJSRuntime\n\n`AxJSRuntime` is the built-in JavaScript runtime used by RLM and tool-style execution.\nIt works across:\n\n- Node.js/Bun-style backends (worker_threads runtime path)\n- Deno backends (module worker path)\n- Browser environments (Web Worker path)\n\nIt supports:\n\n- Persistent sessions via `createSession()`\n- Function tool usage via `toFunction()`\n- Sandbox permissions via `AxJSRuntimePermission`\n\n### Multi-modal (images, audio)\n\n```typescript\nconst analyzer = ax(`\n  image:image, question:string -\u003e\n  description:string,\n  mainColors:string[],\n  category:class \"electronics, clothing, food, other\",\n  estimatedPrice:string\n`);\n```\n\n## Install\n\n```bash\nnpm install @ax-llm/ax\n```\n\nAdditional packages:\n\n```bash\n# AWS Bedrock provider\nnpm install @ax-llm/ax-ai-aws-bedrock\n\n# Vercel AI SDK v5 integration\nnpm install @ax-llm/ax-ai-sdk-provider\n\n# Tools: MCP stdio transport, JS runtime\nnpm install @ax-llm/ax-tools\n```\n\n## Features\n\n- **15+ LLM Providers** – OpenAI, Anthropic, Google, Mistral, Ollama, and more\n- **Type-safe** – Full TypeScript support with auto-completion\n- **Streaming** – Real-time responses with validation\n- **Multi-modal** – Images, audio, text in the same signature\n- **Optimization** – Automatic prompt tuning with MiPRO, ACE, GEPA\n- **Observability** – OpenTelemetry tracing built-in\n- **Workflows** – Compose complex pipelines with AxFlow\n- **RAG** – Multi-hop retrieval with quality loops\n- **Agents** – Tools and multi-agent collaboration\n- **RLM in AxAgent** – Long-context analysis with recursive runtime loops\n- **Zero dependencies** – Lightweight, fast, reliable\n\n## Documentation\n\n**Get Started**\n- [Quick Start Guide](https://github.com/ax-llm/ax/blob/main/src/ax/README.md) – Set up in 5 minutes\n- [Examples Guide](https://github.com/ax-llm/ax/blob/main/src/docs/src/content/docs/examples.md) – Comprehensive examples\n- [DSPy Concepts](https://github.com/ax-llm/ax/blob/main/src/docs/src/content/docs/dspy.md) – Understanding the approach\n- [Signatures Guide](https://github.com/ax-llm/ax/blob/main/src/ax/skills/ax-signature.md) – Type-safe signature design\n\n**Deep Dives**\n- [AI Providers](https://github.com/ax-llm/ax/blob/main/src/ax/skills/ax-ai.md) – All providers, AWS Bedrock, Vercel AI SDK\n- [AxFlow Workflows](https://github.com/ax-llm/ax/blob/main/src/ax/skills/ax-flow.md) – Build complex AI systems\n- [Optimization (MiPRO, ACE, GEPA)](https://github.com/ax-llm/ax/blob/main/src/docs/src/content/docs/optimize.md) – Make programs smarter\n- [AxAgent \u0026 RLM](https://github.com/ax-llm/ax/blob/main/src/ax/skills/ax-agent.md) – Agents, child agents, tools, and RLM for long contexts\n- [Advanced RAG](https://github.com/ax-llm/ax/blob/main/src/docs/src/content/docs/axrag.md) – Production search and retrieval\n\n## Run Examples\n\n```bash\nOPENAI_APIKEY=your-key npm run tsx ./src/examples/[example-name].ts\n```\n\nCore examples: `extract.ts`, `react.ts`, `agent.ts`, `streaming1.ts`, `multi-modal.ts`\n\nProduction patterns: `customer-support.ts`, `food-search.ts`, `rlm.ts`, `ace-train-inference.ts`, `ax-flow-enhanced-demo.ts`\n\n[View all 70+ examples](src/examples/)\n\n## Community\n\n- [Twitter](https://twitter.com/dosco) – Updates\n- [Discord](https://discord.gg/DSHg3dU7dW) – Help and discussion\n- [GitHub](https://github.com/ax-llm/ax) – Star the project\n- [DeepWiki](https://deepwiki.com/ax-llm/ax) – AI-powered docs\n\n## Production Ready\n\n- Battle-tested in production\n- Stable minor versions\n- Comprehensive test coverage\n- OpenTelemetry built-in\n- TypeScript first\n\n## Contributors\n\n- Author: [@dosco](https://github.com/dosco)\n- GEPA and ACE optimizers: [@monotykamary](https://github.com/monotykamary)\n\n## License\n\nApache 2.0\n\n---\n\n```bash\nnpm install @ax-llm/ax\n```\n","funding_links":[],"categories":["TypeScript","NLP","A01_文本生成_文本对话","ai"],"sub_categories":["大语言对话模型及数据"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fax-llm%2Fax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fax-llm%2Fax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fax-llm%2Fax/lists"}