@ax-llm/ax 21.0.12 → 21.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ax-llm/ax",
3
- "version": "21.0.12",
3
+ "version": "21.0.13",
4
4
  "type": "module",
5
5
  "description": "The best library to work with LLMs",
6
6
  "repository": {
@@ -1,16 +1,17 @@
1
1
  ---
2
2
  name: ax-agent-memory-skills
3
- description: This skill helps an LLM generate correct AxAgent memory retrieval and dynamic skill-loading code using @ax-llm/ax. Use when the user asks about onMemoriesSearch, recall(...), inputs.memories, onLoadedMemories, onUsedMemories, onSkillsSearch, discover({ skills }), onLoadedSkills, onUsedSkills, preloaded skills, loaded memory/skill IDs, or carrying memories across forward() calls.
4
- version: "21.0.12"
3
+ description: This skill helps an LLM generate correct AxAgent memory retrieval, context-map, and dynamic skill-loading code using @ax-llm/ax. Use when the user asks about contextMap, AxAgentContextMap, onMemoriesSearch, recall(...), inputs.memories, onLoadedMemories, onUsedMemories, onSkillsSearch, discover({ skills }), onLoadedSkills, onUsedSkills, preloaded skills, loaded memory/skill IDs, or carrying memories across forward() calls.
4
+ version: "21.0.13"
5
5
  ---
6
6
 
7
7
  # AxAgent Memory And Skills Rules (@ax-llm/ax)
8
8
 
9
- Use this skill when an agent needs to retrieve task-relevant memories or load skill guides into the executor prompt on demand. For ordinary agent setup use `ax-agent`. For RLM runtime policy use `ax-agent-rlm`. For callbacks and telemetry use `ax-agent-observability`.
9
+ Use this skill when an agent needs a persistent context map, task-relevant memory retrieval, or skill guides loaded into the executor prompt on demand. For ordinary agent setup use `ax-agent`. For RLM runtime policy use `ax-agent-rlm`. For callbacks and telemetry use `ax-agent-observability`.
10
10
 
11
11
  ## Use These Defaults
12
12
 
13
13
  - Use `onMemoriesSearch` when the agent should pull relevant context from an external store instead of stuffing everything into the prompt upfront.
14
+ - Use `contextMap` when repeated runs inspect the same long external context and should accumulate a small orientation cache automatically.
14
15
  - Use `onSkillsSearch` when the agent should load usage guides, runbooks, or domain conventions into the executor prompt on demand.
15
16
  - `recall(...)` is available to distiller and executor stages when `onMemoriesSearch` is set.
16
17
  - `discover({ skills })` is available to the executor when `onSkillsSearch` is set.
@@ -19,6 +20,53 @@ Use this skill when an agent needs to retrieve task-relevant memories or load sk
19
20
  - Use `onUsedMemories` / `onUsedSkills` to track what the actor says it actually relied on.
20
21
  - Child agents do not inherit memory or skills search callbacks; wire them explicitly on every agent that needs the capability.
21
22
 
23
+ ## Context Map
24
+
25
+ Use `contextMap` when repeated runs ask different questions over the same long context, document set, or repository. The map is prompt-resident orientation knowledge: structure, concepts, constants, parsing schema, reusable aggregate results, and concrete error patterns. It is not a task-specific answer cache.
26
+
27
+ Runnable example: [`src/examples/rlm-context-map.ts`](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-context-map.ts) demonstrates one update, `onUpdate` snapshot persistence, finite evolve, and frozen map reuse.
28
+
29
+ When `contextMap` is configured:
30
+
31
+ - Ax injects the current map into the distiller prompt.
32
+ - Ax updates the map once after each successful completed `forward(...)`.
33
+ - By default the map evolves forever. For a finite warmup, create the map with `{ infiniteEvolve: false, evolveSteps: N }`; after `N` successful updates it is still injected but no longer updated.
34
+ - Failed runs, aborts, and clarification requests do not update the map.
35
+ - Use `onUpdate` to persist `result.map.snapshot()` outside the agent.
36
+
37
+ ```typescript
38
+ import { agent, AxAgentContextMap } from '@ax-llm/ax';
39
+
40
+ const map = new AxAgentContextMap(savedSnapshot, {
41
+ maxChars: 4000,
42
+ infiniteEvolve: false,
43
+ evolveSteps: 10,
44
+ });
45
+
46
+ const myAgent = agent('context:string, query:string -> answer:string', {
47
+ contextFields: ['context'],
48
+ contextMap: {
49
+ map,
50
+ onUpdate: ({ map }) => saveSnapshot(map.snapshot()),
51
+ },
52
+ });
53
+ ```
54
+
55
+ Types:
56
+
57
+ ```typescript
58
+ type AxAgentContextMapConfig = {
59
+ map?: AxAgentContextMap | AxAgentContextMapSnapshot | string;
60
+ onUpdate?: (result: AxAgentContextMapUpdateResult) => void | Promise<void>;
61
+ };
62
+
63
+ type AxAgentContextMapOptions = {
64
+ maxChars?: number;
65
+ infiniteEvolve?: boolean;
66
+ evolveSteps?: number;
67
+ };
68
+ ```
69
+
22
70
  ## Memory Search
23
71
 
24
72
  Use `onMemoriesSearch` when the agent needs to pull task-relevant context such as user preferences, prior decisions, project facts, or past conversations from an external store (vector DB, BM25, KV). The actor decides what to load, when, and how much.
@@ -268,6 +316,7 @@ onUsedSkills?: (
268
316
  usedSkills: readonly AxAgentUsedSkill[]
269
317
  ) => void | Promise<void>;
270
318
 
319
+ contextMap?: AxAgentContextMapConfig;
271
320
  skills?: readonly AxAgentSkillResult[];
272
321
  ```
273
322
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-agent-observability
3
3
  description: This skill helps an LLM generate correct AxAgent observability code using @ax-llm/ax. Use when the user asks about actorTurnCallback, executorTurnCallback, onContextEvent, agentStatusCallback, onFunctionCall, reportSuccess, reportFailure, getChatLog(), getUsage(), resetUsage(), debug traces, progress updates, or telemetry for AxAgent runs.
4
- version: "21.0.12"
4
+ version: "21.0.13"
5
5
  ---
6
6
 
7
7
  # AxAgent Observability Rules (@ax-llm/ax)
@@ -66,7 +66,7 @@ Important:
66
66
  - `result` is the raw runtime result before Ax applies type-aware serialization and budget-proportional truncation.
67
67
  - `thought` is optional and only appears when the underlying `AxGen` call had `showThoughts` enabled and the provider actually returned a thought field.
68
68
  - `actionLogEntryCount` and `guidanceLogEntryCount` reflect the live log sizes after the turn is processed, including resumed runs.
69
- - `actorTurnCallback` fires for the root agent and for recursive child agents that run actor turns.
69
+ - `actorTurnCallback` fires for the configured agent instance. Child agents passed through `functions: [...]` should define their own callback if you need their internal actor turns; use `onFunctionCall` on the parent to observe the parent-side child-agent invocation.
70
70
 
71
71
  Good pattern:
72
72
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-agent-optimize
3
- description: This skill helps an LLM generate correct AxAgent tuning and evaluation code using @ax-llm/ax. Use when the user asks about agent.optimize(...), judgeOptions, eval datasets, optimization targets, saved optimizedProgram artifacts, or recursive optimization guidance.
4
- version: "21.0.12"
3
+ description: This skill helps an LLM generate correct AxAgent tuning and evaluation code using @ax-llm/ax. Use when the user asks about agent.optimize(...), judgeOptions, eval datasets, optimization targets, saved optimizedProgram artifacts, or agent optimization guidance.
4
+ version: "21.0.13"
5
5
  ---
6
6
 
7
7
  # AxAgent Optimize Codegen Rules (@ax-llm/ax)
@@ -13,7 +13,7 @@ Your job is to help the model choose a good optimization setup for the user's ac
13
13
  - If the user wants better tool use, prefer action-aware tasks and either a deterministic metric or the built-in judge depending on how objective the scoring is.
14
14
  - If the user wants better wording only, responder optimization may be enough.
15
15
  - If the user wants reusable improvements, include artifact save/load.
16
- - If the user wants cost or recursion behavior improved, make the eval tasks expose those tradeoffs explicitly.
16
+ - If the user wants cost, tool-use, or child-agent delegation behavior improved, make the eval tasks expose those tradeoffs explicitly.
17
17
 
18
18
  ## Use These Defaults
19
19
 
@@ -32,7 +32,7 @@ Your job is to help the model choose a good optimization setup for the user's ac
32
32
  - For first examples, pass a plain task array instead of splitting into `train` and `validation` unless the user already has a holdout set.
33
33
  - GEPA-backed `agent.optimize(...)` now optimizes generic components exposed by the selected target programs; `target: 'actor'` only tunes actor components, `target: 'responder'` only tunes responder components, and `target: 'all'` broadens the component set.
34
34
  - `result.optimizedProgram.componentMap` is the canonical saved artifact for agent GEPA runs. It may include actor instructions, descriptions, tool descriptions/names, templates, or runtime primitives depending on what the selected target exposes.
35
- - When recursive behavior matters, keep `mode: 'advanced'` on the agent and tune against realistic `recursionOptions`.
35
+ - When child-agent delegation matters, expose the child agents as named functions and tune against realistic call/no-call tasks.
36
36
 
37
37
  ## Decision Guide
38
38
 
@@ -41,7 +41,7 @@ Pick the optimization shape from the user's need:
41
41
  - "Make the agent use tools correctly" -> keep the default actor target and use `expectedActions` and `forbiddenActions`.
42
42
  - "Make final answers read better" -> consider `target: 'responder'`, but only if the task is not mostly tool-selection or clarification behavior.
43
43
  - "Make the whole agent better" -> use the default actor target first; only broaden target selection when the user clearly wants that extra scope.
44
- - "Tune recursive delegation" -> keep `mode: 'advanced'` and use tasks that actually exercise recursion depth, fan-out, and termination choices.
44
+ - "Tune child-agent delegation" -> use tasks that exercise when to call the child agent, when to call normal tools, and when to answer directly.
45
45
  - "Compare before and after" -> include a held-out task plus artifact save/load and replay.
46
46
 
47
47
  Choose task design carefully:
@@ -58,8 +58,8 @@ Optimization works much better when the agent and dataset remove avoidable ambig
58
58
  - Prefer typed tool outputs over free-form JSON blobs so the actor can rely on exact field names.
59
59
  - Tell the actor the exact tool fields it may use when payload shape matters.
60
60
  - Explicitly ban invented fields if the model has any reason to guess hidden IDs or alternate key names.
61
- - If recursive children only see explicit `llmQuery(..., context)` payloads, say that directly in the actor prompt.
62
- - For recursive synthesis, tell the agent what the narrowed context should look like before delegation.
61
+ - If a child agent needs parent values, declare those fields in the child signature and pass them explicitly at the call site.
62
+ - For specialist synthesis, tell the agent what narrowed context should be passed to the child agent.
63
63
  - Keep `maxSubAgentCalls` small in examples unless the user is explicitly testing broad fan-out behavior.
64
64
  - Use canonical, unambiguous task wording so the model does not burn turns asking for fake clarification.
65
65
  - In JS-runtime agents, require raw runnable JavaScript only. Ban `javascript:` prefixes, mixed prose/code, and multi-snippet turns.
@@ -68,14 +68,14 @@ Good pattern:
68
68
 
69
69
  - tool schema says exactly what fields exist
70
70
  - task names the exact entity to look up
71
- - actor prompt says which fields to extract before delegation
72
- - metric or judge penalizes unnecessary recursion and tool misuse
71
+ - actor prompt says which fields to extract before calling a child agent
72
+ - metric or judge penalizes unnecessary child-agent calls and tool misuse
73
73
 
74
74
  Bad pattern:
75
75
 
76
76
  - tool returns `json` with an underspecified shape
77
77
  - task uses overloaded names like `Atlas` without clarifying whether that is a project, team, or account
78
- - recursive child is expected to infer hidden parent state that was never passed in context
78
+ - child agent is expected to infer hidden parent state that was never passed in its call arguments
79
79
  - code agent is allowed to mix natural language with JavaScript in the same turn
80
80
 
81
81
  ## Metric vs Judge
@@ -149,7 +149,7 @@ const assistant = agent('query:string -> answer:string', {
149
149
  judgeAI,
150
150
  contextFields: [],
151
151
  runtime: new AxJSRuntime(),
152
- functions: { local: tools },
152
+ functions: tools,
153
153
  contextPolicy: { preset: 'checkpointed', budget: 'balanced' },
154
154
  judgeOptions: {
155
155
  description: 'Prefer correct tool use over polished wording.',
@@ -222,7 +222,7 @@ const result = await assistant.optimize(tasks, {
222
222
  score += 0.4;
223
223
  }
224
224
 
225
- if ((prediction.recursiveStats?.recursiveCallCount ?? 0) === 0) {
225
+ if (prediction.turnCount <= 3) {
226
226
  score += 0.2;
227
227
  }
228
228
 
@@ -234,7 +234,7 @@ const result = await assistant.optimize(tasks, {
234
234
  Use this pattern when:
235
235
 
236
236
  - the task has a known correct answer or exact action pattern
237
- - recursion cost or tool count must be measured explicitly
237
+ - tool count, child-agent calls, or turn count must be measured explicitly
238
238
  - you want repeatable, low-variance optimization runs
239
239
 
240
240
  ## Built-In Judge Pattern
@@ -247,7 +247,7 @@ const result = await assistant.optimize(tasks, {
247
247
  judgeOptions: {
248
248
  model: AxAIGoogleGeminiModel.Gemini3Pro,
249
249
  description:
250
- 'Be strict about unnecessary delegation, weak clarifications, and incorrect tool choices.',
250
+ 'Be strict about unnecessary child-agent calls, weak clarifications, and incorrect tool choices.',
251
251
  },
252
252
  maxMetricCalls: 12,
253
253
  });
@@ -306,7 +306,6 @@ Use this pattern when:
306
306
  - Use `expectedActions` and `forbiddenActions` when tool correctness matters.
307
307
  - `judgeOptions` mirrors normal forward options and supports extra judge guidance through `description`.
308
308
  - The built-in judge scores from the full agent run, not just the final reply. It can see completion type, clarification payload, final output, action log, normalized function calls, tool errors, and turn count.
309
- - For recursive advanced-mode evals, the built-in judge can also see `recursiveTrace` and `recursiveStats`.
310
309
  - If the user provides a custom `metric`, that overrides the built-in judge path.
311
310
  - If the user provides an LLM-based custom metric, keep the output schema as small as possible and prefer a direct numeric score.
312
311
 
@@ -326,16 +325,13 @@ Decision rules:
326
325
  - For final outcomes in custom metrics, expect `prediction.completionType === 'final'` and populated `prediction.output`.
327
326
  - `target: 'responder'` still works, but clarification-heavy tasks are usually low-signal for responder optimization.
328
327
 
329
- ## Recursive Optimization Notes
328
+ ## Delegation Optimization Notes
330
329
 
331
- - Recursive-slot artifacts require an agent configured for recursive advanced mode.
332
- - Keep `mode: 'advanced'` top-level; child recursion behavior still follows `recursionOptions`.
333
- - When recursive behavior matters, tune against the same `maxDepth` and tool/discovery structure you expect in production.
334
- - Use recursive traces and recursive stats when the user wants to diagnose where token or delegation cost is coming from.
335
- - For recursion-efficiency tuning, prefer a deterministic metric unless the user specifically needs a qualitative LLM review of decomposition quality.
336
- - Tell the actor that recursive children only see passed context, not parent globals or prior tool results.
337
- - For synthesis-style recursive tasks, specify the desired delegation pattern explicitly, for example "use at most one focused delegated child analysis after narrowing the tool output in JS."
338
- - Penalize over-decomposition directly in the metric or judge prompt.
330
+ - Prefer explicit child agents in `functions: [...]` for specialist delegation. Their calls appear as normal function-call records.
331
+ - When delegation behavior matters, tune against the same child-agent/tool structure you expect in production.
332
+ - Tell the actor which fields to pass to the child agent and which tasks should stay local.
333
+ - For synthesis-style tasks, specify the desired delegation pattern explicitly, for example "call `team.writer(...)` only after narrowing tool output in JS."
334
+ - Penalize unnecessary child-agent calls directly in the metric or judge prompt.
339
335
  - If one training task keeps collapsing to zero, inspect that task first instead of adding more optimizer rounds. Most failures come from task ambiguity, weak tool schemas, or vague delegation guidance rather than GEPA itself.
340
336
 
341
337
  ## Artifacts And Replay
@@ -350,7 +346,6 @@ Decision rules:
350
346
 
351
347
  - [RLM Agent Optimize](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-agent-optimize.ts) — Gemini office-assistant tuning with save/load
352
348
  - [AxAgent GEPA Component Optimization](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/axagent-gepa-optimization.ts) — compact support-agent GEPA run with deterministic metric and artifact replay
353
- - [RLM Agent Recursive Optimize](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-agent-recursive-optimize.ts) — recursive-slot optimization artifacts
354
349
 
355
350
  ## Do Not Generate
356
351
 
@@ -358,6 +353,6 @@ Decision rules:
358
353
  - Do not recommend responder-only optimization by default for clarification-heavy workflows.
359
354
  - Do not omit artifact save/load steps when the user asks for reusable optimized configurations.
360
355
  - Do not introduce a dedicated judge class or helper abstraction in new agent-optimize examples; prefer the built-in judge path or a plain typed `AxGen`.
361
- - Do not rely on vague `json` tool returns when the agent must reason about specific fields across recursive steps.
362
- - Do not leave recursive child context implicit. If the child needs a fact, pass it explicitly.
356
+ - Do not rely on vague `json` tool returns when the agent must reason about specific fields across tool or child-agent calls.
357
+ - Do not leave child-agent inputs implicit. If the child needs a fact, pass it explicitly.
363
358
  - Do not let code-generation agents mix prose and JavaScript if the user is optimizing runtime behavior.
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  name: ax-agent-rlm
3
- description: This skill helps an LLM generate correct AxAgent RLM/runtime code using @ax-llm/ax. Use when the user asks about RLM code execution, AxJSRuntime, contextFields, contextPolicy, liveRuntimeState, promptLevel, stage prompt controls, executorModelPolicy, maxRuntimeChars, agent.test(...), llmQuery(...), mode: 'advanced', recursionOptions, or long-running agent runtime behavior.
4
- version: "21.0.12"
3
+ description: This skill helps an LLM generate correct AxAgent RLM/runtime code using @ax-llm/ax. Use when the user asks about RLM code execution, AxJSRuntime, contextFields, contextPolicy, liveRuntimeState, promptLevel, stage prompt controls, executorModelPolicy, maxRuntimeChars, agent.test(...), llmQuery(...), recursionOptions, or long-running agent runtime behavior.
4
+ version: "21.0.13"
5
5
  ---
6
6
 
7
7
  # AxAgent RLM Runtime Rules (@ax-llm/ax)
8
8
 
9
- Use this skill for code-runtime agents and recursive/delegated runtime behavior. For ordinary agent setup, child agents, tool namespaces, clarification, and `bubbleErrors`, use `ax-agent`. For callbacks and logs, use `ax-agent-observability`. For memories and skill loading, use `ax-agent-memory-skills`.
9
+ Use this skill for code-runtime agents and `llmQuery(...)` semantic-helper behavior. For ordinary agent setup, child agents, tool namespaces, clarification, and `bubbleErrors`, use `ax-agent`. For callbacks and logs, use `ax-agent-observability`. For memories and skill loading, use `ax-agent-memory-skills`.
10
10
 
11
11
  ## Use These Defaults
12
12
 
@@ -14,11 +14,13 @@ Use this skill for code-runtime agents and recursive/delegated runtime behavior.
14
14
  - In stdout-mode RLM, use one observable `console.log(...)` step per non-final actor turn.
15
15
  - Default to `contextPolicy: { preset: 'checkpointed', budget: 'balanced' }` for most RLM tasks.
16
16
  - Prefer `contextPolicy: { preset: 'adaptive', budget: 'balanced' }` when older successful turns should collapse sooner while live runtime state stays visible.
17
+ - Use `contextMap` for recurring long-context corpora when the distiller should start future runs with a small persisted orientation cache.
17
18
  - Prefer `promptLevel: 'default'` for normal use.
18
19
  - Use `promptLevel: 'detailed'` when you want extra anti-pattern examples and tighter teaching scaffolding in the actor prompt.
19
20
  - Prefer `executorModelPolicy` when the actor may need to upgrade after repeated error turns or discovery in specific namespaces without also upgrading the responder.
20
- - Prefer `mode: 'simple'` unless recursive child agents materially improve the task.
21
- - Prefer `maxSubAgentCalls` only when advanced recursion is enabled or the user needs explicit delegation limits.
21
+ - Use explicit child agents in `functions: [...]` when the task needs specialist agents with their own tools/runtime.
22
+ - Use `llmQuery(...)` only for focused semantic questions over narrowed context; it does not spawn a tool-using child AxAgent.
23
+ - Prefer `maxSubAgentCalls` only when you need an explicit cap on `llmQuery(...)` sub-query usage.
22
24
 
23
25
  ## Mental Model
24
26
 
@@ -131,14 +133,14 @@ Practical rule:
131
133
 
132
134
  Use these top-level controls consistently:
133
135
 
134
- - `mode`: controls whether `llmQuery(...)` stays simple or delegates to recursive child agents in advanced mode.
135
- - `recursionOptions.maxDepth`: limits recursive `llmQuery(...)` depth.
136
- - `recursionOptions.ai`: routes recursive `llmQuery(...)` sub-agent calls to a different AI service than the parent run.
137
- - `maxSubAgentCalls`: shared delegated-call budget across the whole run, including recursive children. Default is `100`.
136
+ - `recursionOptions.ai`: routes `llmQuery(...)` sub-query calls to a different AI service than the parent run.
137
+ - `recursionOptions.model`, `modelConfig`, and other forward options: tune the AxGen call used by `llmQuery(...)`.
138
+ - `maxSubAgentCalls`: shared `llmQuery(...)` sub-query budget across the whole run. Default is `100`.
138
139
  - `maxBatchedLlmQueryConcurrency`: caps batched `llmQuery([...])` concurrency.
139
140
  - `maxRuntimeChars`: runtime/output truncation ceiling for console logs, tool results, and interpreter output replay. The effective limit is computed dynamically each turn based on remaining context budget.
140
141
  - `summarizerOptions`: default model/options for the internal checkpoint summarizer.
141
142
  - `contextPolicy`: replay/checkpointing/compression policy.
143
+ - `contextMap`: optional persistent orientation cache injected into the distiller and updated once after each successful run. `AxAgentContextMap` evolves indefinitely by default; use `{ infiniteEvolve: false, evolveSteps: N }` on the map object for finite warmup followed by reuse.
142
144
  - `contextOptions`: distiller-stage forward options.
143
145
  - `executorOptions`: executor-stage forward options such as `description`, `model`, `modelConfig`, `thinkingTokenBudget`, and `showThoughts`.
144
146
  - `executorModelPolicy`: executor-only model override rules based on consecutive error turns or discovery fetches from listed namespaces.
@@ -151,9 +153,8 @@ Canonical shape:
151
153
  const researchAgent = agent('query:string -> answer:string', {
152
154
  contextFields: ['query'],
153
155
  runtime,
154
- mode: 'advanced',
155
156
  recursionOptions: {
156
- maxDepth: 2,
157
+ model: 'gpt-5.4-mini',
157
158
  },
158
159
  maxRuntimeChars: 3000,
159
160
  summarizerOptions: {
@@ -187,16 +188,14 @@ const researchAgent = agent('query:string -> answer:string', {
187
188
 
188
189
  Semantics:
189
190
 
190
- - `mode` stays top-level; there is no `recursionOptions.mode`.
191
191
  - `maxRuntimeChars` sets the truncation ceiling and is separate from `contextPolicy.budget`.
192
192
  - `summarizerOptions` tunes only the internal checkpoint summarizer. It does not change actor or responder model selection.
193
193
  - `executorModelPolicy` only switches the actor model. It does not change `responderOptions.model`.
194
- - Recursive child agents can inherit `executorModelPolicy`; use a child override only when that child needs different routing behavior.
195
- - Recursive child calls use `recursionOptions.ai` when set, otherwise they fall back to the parent `.forward(ai, ...)` service.
194
+ - `llmQuery(...)` uses `recursionOptions.ai` when set, otherwise it falls back to the parent `.forward(ai, ...)` service.
195
+ - `recursionOptions` configures the AxGen semantic sub-query used by `llmQuery(...)`; it does not create a child AxAgent and cannot give the sub-query tools.
196
196
  - `executorModelPolicy` entries are ordered from weaker to stronger. If multiple rules match, the last matching entry wins.
197
197
  - If one entry defines `namespaces`, any successful `discover(...)` function-definition fetch from one of those namespaces marks the rule as matched starting on the next actor turn.
198
- - Do not add `mode: 'advanced'` just because recursion exists as a feature. Add it only when delegated children need their own tool/discovery/runtime loop.
199
- - Do not add `recursionOptions` if the user does not need recursive delegation.
198
+ - Do not add `recursionOptions` unless the user needs different model/options for `llmQuery(...)`.
200
199
 
201
200
  ## Dynamic Output Truncation
202
201
 
@@ -365,20 +364,12 @@ Available forms:
365
364
  Rules:
366
365
 
367
366
  - `llmQuery(...)` forwards only the explicit `context` argument.
368
- - Parent inputs are not automatically available to `llmQuery(...)` children.
369
- - In `mode: 'simple'`, `llmQuery(...)` is a direct semantic helper.
370
- - In `mode: 'advanced'`, `llmQuery(...)` delegates a focused subtask to a child `AxAgent` with its own runtime and action log while recursion depth remains.
371
- - In advanced mode, no parent `contextFields` are auto-inserted into recursive children. Only explicit `llmQuery(..., context)` payload is available there.
372
- - If `context` is a plain object, safe keys are exposed as child runtime globals and the full payload is also available as `context`.
373
- - In advanced mode, use `llmQuery(...)` to offload discovery-heavy, tool-heavy, or multi-turn semantic branches so the parent action log stays smaller and more focused.
374
- - In advanced mode, use batched `llmQuery([...])` only for independent subtasks. Use serial calls when later work depends on earlier results.
375
- - In advanced mode with discovery enabled, prefer putting noisy tool discovery, `discover(...)`, and branch-specific tool chatter inside delegated child calls when those branches are independent or semantically distinct.
376
- - In advanced mode, pass compact named object context to children instead of huge raw parent payloads.
377
- - In advanced mode, do not assume child-created variables, discovered docs, or action-log history come back to the parent. Only the child return value comes back.
378
- - In advanced mode, if a child calls `askClarification(...)`, that clarification bubbles up and ends the top-level run.
379
- - In advanced mode, recursion is depth-limited: `maxDepth: 0` makes top-level `llmQuery(...)` simple; `maxDepth: 1` makes top-level `llmQuery(...)` advanced and child `llmQuery(...)` simple.
380
- - In advanced mode, batched delegated children are cancelled when a sibling child asks for clarification or aborts, so use batched form only when branches are truly independent.
381
- - `maxSubAgentCalls` is a shared budget across the whole top-level run, including recursive children.
367
+ - Parent inputs, runtime variables, tool results, and discovered docs are not automatically available to `llmQuery(...)`; include any needed facts in `context`.
368
+ - `llmQuery(...)` is a direct semantic helper backed by an AxGen sub-query. It does not create a child AxAgent, does not run a JS runtime, and does not have access to tools or discovery.
369
+ - Use batched `llmQuery([...])` only for independent semantic questions. Use serial calls when later work depends on earlier results.
370
+ - Pass compact named object context instead of huge raw parent payloads.
371
+ - Do not assume anything other than the returned string comes back from `llmQuery(...)`.
372
+ - `maxSubAgentCalls` is a shared budget for `llmQuery(...)` sub-queries across the top-level run.
382
373
  - Single-call `llmQuery(...)` may return `[ERROR] ...` on non-abort failures.
383
374
  - Batched `llmQuery([...])` returns per-item `[ERROR] ...`.
384
375
  - If a result starts with `[ERROR]`, inspect or branch on it instead of assuming success.
@@ -394,7 +385,7 @@ if (summary.startsWith('[ERROR]')) {
394
385
  }
395
386
  ```
396
387
 
397
- Advanced recursive discovery example:
388
+ Parallel semantic review example:
398
389
 
399
390
  ```javascript
400
391
  const narrowedIncidents = incidents.map((incident) => ({
@@ -436,23 +427,20 @@ Delegation decision guide:
436
427
 
437
428
  - **JS-only**: deterministic logic such as filter, sort, count, regex, or date math -> do it inline.
438
429
  - **Single-shot semantic**: needs LLM reasoning but no tools or multi-step exploration -> single `llmQuery(...)` with narrow context.
439
- - **Full delegation**: needs its own discovery, tool calls, or more than two turns of exploratory work -> `llmQuery(...)` as child agent.
440
- - **Parallel fan-out**: two or more independent subtasks each qualifying for delegation -> batched `llmQuery([...])`.
430
+ - **Specialist/tool delegation**: needs its own tools, discovery, runtime, or reusable role -> create a child `agent(...)` and pass it in `functions: [...]`.
431
+ - **Parallel semantic fan-out**: two or more independent semantic-only subtasks -> batched `llmQuery([...])`.
441
432
 
442
433
  Context handling:
443
434
 
444
- - In advanced mode, the `context` object is injected into the child's JS runtime as named globals. It does not go into the child's LLM prompt as raw data.
445
- - The child prompt sees only a compact metadata summary of the delegated context.
446
- - The child actor explores the delegated context with code, the same way the parent explores `inputs.*`.
447
435
  - Always narrow with JS before delegating. Never pass raw `inputs.*`.
448
436
  - Name context keys semantically, e.g. `{ emails: filtered, rubric: 'classify-urgency' }`.
449
- - Estimate total sub-agent calls before fanning out. `maxSubAgentCalls` is shared across all recursion levels.
437
+ - Estimate total sub-query calls before fanning out. `maxSubAgentCalls` is shared across the run.
450
438
 
451
439
  Patterns:
452
440
 
453
- - Fan-Out / Fan-In: JS narrows into categories -> `llmQuery([...])` fans out per category -> JS or one more `llmQuery(...)` merges results.
441
+ - Fan-Out / Fan-In: JS narrows into categories -> `llmQuery([...])` fans out per category -> JS or one more `llmQuery(...)` merges semantic results.
454
442
  - Pipeline: serial `llmQuery(...)` calls where each depends on the prior result.
455
- - Scout-then-Execute: first child explores, parent processes with JS, second child acts.
443
+ - Specialist tool use: call child agents or tools via their namespaced function globals, e.g. `await team.writer({ draft })`.
456
444
 
457
445
  ## Examples
458
446
 
@@ -460,8 +448,7 @@ Fetch these for full working code:
460
448
 
461
449
  - [RLM](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm.ts) - RLM basic
462
450
  - [RLM Long Task](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-long-task.ts) - RLM context policy
463
- - [RLM Discovery](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-discovery.ts) - advanced recursive `llmQuery(...)` plus discovery-heavy delegated subtasks
464
- - [RLM Shared Fields](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-shared-fields.ts) - shared fields
451
+ - [RLM Discovery](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-discovery.ts) - discovery mode, grouped tools, child agents as functions, and semantic `llmQuery(...)`
465
452
  - [RLM Adaptive Replay](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-adaptive-replay.ts) - adaptive replay
466
453
  - [RLM Live Runtime State](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-live-runtime-state.ts) - structured runtime-state rendering
467
454
  - [RLM Clarification Resume](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-clarification-resume.ts) - clarification exception plus `getState()` / `setState(...)`
@@ -472,7 +459,7 @@ Fetch these for full working code:
472
459
  - Do not combine `console.log(...)` with `final(...)`.
473
460
  - Do not assume old successful turns stay fully replayed under adaptive/checkpointed/lean policies.
474
461
  - Do not rebuild runtime state just because a prior turn was summarized.
475
- - Do not add `mode: 'advanced'` unless delegated children need their own tool/discovery/runtime loop.
476
- - Do not assume parent inputs are available in `llmQuery(...)` children unless passed in `context`.
462
+ - Do not describe `llmQuery(...)` as spawning a tool-using child AxAgent.
463
+ - Do not assume parent inputs are available to `llmQuery(...)` unless passed in `context`.
477
464
  - Do not ignore `[ERROR] ...` results from `llmQuery(...)`.
478
465
  - Do not grant `AxJSRuntime` permissions unless the user asked for the capability.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-agent
3
3
  description: This skill helps an LLM generate correct core AxAgent code using @ax-llm/ax. Use when the user asks about agent(), child agents, namespaced functions, discovery mode, clarification, bubbleErrors, host-side final/clarification protocol, or ordinary agent runtime behavior. For RLM/code-runtime work use ax-agent-rlm; for callbacks and telemetry use ax-agent-observability; for recall/memory/skill loading use ax-agent-memory-skills; for agent.optimize(...) use ax-agent-optimize.
4
- version: "21.0.12"
4
+ version: "21.0.13"
5
5
  ---
6
6
 
7
7
  # AxAgent Codegen Rules (@ax-llm/ax)
@@ -25,19 +25,18 @@ Your job is to choose the smallest correct `AxAgent` shape for the user's needs:
25
25
  - Prefer namespaced functions such as `utils.search(...)` or `kb.find(...)`.
26
26
  - Pass child agents directly in `functions: [...]`. They land under their `agentIdentity.namespace` (or `utils` if unset), exactly like a `fn()` tool.
27
27
  - If discovery is enabled, call `discover(...)` before using callables whose docs are not already in the prompt.
28
- - Prefer `mode: 'simple'` unless recursive child agents materially improve the task.
29
- - Add `mode: 'advanced'`, `recursionOptions`, or `maxSubAgentCalls` only when delegated children need their own runtime, tools, or discovery loop.
28
+ - Use explicit child agents in `functions: [...]` for specialist delegation; do not model that as recursive `llmQuery(...)`.
30
29
  - Add `bubbleErrors` only for fatal infrastructure errors that should abort `.forward()`.
31
30
 
32
31
  ## Decision Guide
33
32
 
34
33
  Map user intent to agent shape before writing code:
35
34
 
36
- - "Use tools and answer" -> plain `agent(...)` with local functions, no recursion, no extra observability.
35
+ - "Use tools and answer" -> plain `agent(...)` with local functions, no extra observability.
37
36
  - "Need child agents with distinct responsibilities" -> add child agents to the parent's `functions: [...]` list and set each child's `agentIdentity.namespace` when you want a specific runtime call site such as `team.writer(...)`.
38
37
  - "Need tool discovery because names/schemas are not stable" -> enable discovery and generate discovery-first actor code.
39
- - "Need certain errors to escape the agent loop" -> add `bubbleErrors` with error classes; those errors propagate through function handlers, actor code, and `llmQuery(...)` sub-agents to `.forward()`.
40
- - "Inspect large context with code", "RLM", "`llmQuery(...)`", or "recursive delegation" -> use `ax-agent-rlm`.
38
+ - "Need certain errors to escape the agent loop" -> add `bubbleErrors` with error classes; those errors propagate through function handlers, actor code, and `llmQuery(...)` sub-queries to `.forward()`.
39
+ - "Inspect large context with code", "RLM", or "`llmQuery(...)`" -> use `ax-agent-rlm`.
41
40
  - "Need debugging, traces, progress updates, tool-call logs, chat logs, or usage" -> use `ax-agent-observability`.
42
41
  - "Need memories, recall, dynamic skill guides, `discover({ skills })`, or loaded/used tracking" -> use `ax-agent-memory-skills`.
43
42
 
@@ -51,6 +50,7 @@ Map user intent to agent shape before writing code:
51
50
  - When resuming after clarification, prefer `error.getState()` from the thrown `AxAgentClarificationError`, then call `agent.setState(savedState)` before the next `forward(...)`.
52
51
  - Errors listed in `bubbleErrors` bypass actor-loop catch blocks and propagate directly to the caller of `.forward()`.
53
52
  - Child agents receive only the arguments the actor passes. Pass parent fields explicitly via `inputs.<field>` or use `inputUpdateCallback` when many calls need the same value.
53
+ - Audio input fields are transcribed before agent planner/executor/responder stages by default; internal agent stages receive text transcripts, not base64 audio.
54
54
 
55
55
  ## Canonical Pattern
56
56
 
@@ -80,6 +80,42 @@ const result = await assistant.forward(llm, { query: 'What is TypeScript?' });
80
80
  console.log(result.answer);
81
81
  ```
82
82
 
83
+ ## Audio Inputs And Speech Outputs
84
+
85
+ Agents can accept audio inputs and return scripted speech artifacts. The runtime transcribes audio input fields before internal stages run, then synthesizes `:audio` outputs after the final structured response is selected.
86
+
87
+ ```typescript
88
+ const voiceAgent = agent(
89
+ 'recording:audio, question:string -> speech:audio, summary:string',
90
+ {
91
+ agentIdentity: {
92
+ name: 'Voice Assistant',
93
+ description: 'Answers spoken requests',
94
+ },
95
+ contextFields: [],
96
+ }
97
+ );
98
+
99
+ const result = await voiceAgent.forward(
100
+ llm,
101
+ {
102
+ recording: { data: base64Wav, format: 'wav' },
103
+ question: 'What should I do next?',
104
+ },
105
+ {
106
+ speech: {
107
+ transcribe: { model: 'gpt-4o-mini-transcribe' },
108
+ speak: { voice: 'alloy', format: 'mp3' },
109
+ },
110
+ }
111
+ );
112
+
113
+ console.log(result.summary);
114
+ console.log(result.speech.data);
115
+ ```
116
+
117
+ Use direct `ax(...)` or `.chat()` if the model should receive native audio instead of a transcript-first agent pipeline.
118
+
83
119
  ## Child Agents As Tools
84
120
 
85
121
  Child agents are passed in the parent's `functions` list. There is no separate `agents` option for new code. Each child agent's `agentIdentity.namespace` (or `utils`, the default) determines where it lands in the JS runtime:
@@ -333,7 +369,7 @@ State notes:
333
369
 
334
370
  ## Bubble Errors
335
371
 
336
- Use `bubbleErrors` when certain exceptions thrown inside function handlers or `llmQuery(...)` sub-agent calls should propagate all the way out to `.forward()` instead of being caught by the actor loop and returned as `[ERROR]` strings.
372
+ Use `bubbleErrors` when certain exceptions thrown inside function handlers or `llmQuery(...)` sub-query calls should propagate all the way out to `.forward()` instead of being caught by the actor loop and returned as `[ERROR]` strings.
337
373
 
338
374
  ```typescript
339
375
  import { agent, f, fn } from '@ax-llm/ax';
@@ -366,8 +402,7 @@ const myAgent = agent('query:string -> answer:string', {
366
402
  Rules:
367
403
 
368
404
  - `bubbleErrors` takes an array of Error constructor classes, checked via `instanceof`.
369
- - A matching error thrown inside a function handler, during actor code execution, or inside a nested `llmQuery(...)` child agent propagates immediately to `.forward()`.
370
- - The same `bubbleErrors` list is automatically propagated to recursive child agents created for advanced-mode `llmQuery(...)` calls.
405
+ - A matching error thrown inside a function handler, during actor code execution, or inside an `llmQuery(...)` sub-query propagates immediately to `.forward()`.
371
406
  - Use `bubbleErrors` for fatal infrastructure errors such as DB down, auth failure, or quota exceeded.
372
407
  - Do not use `bubbleErrors` for expected recoverable errors; let those return as `[ERROR] ...` strings so the actor can handle them.
373
408
  - `AxAgentClarificationError` and `AxAIServiceAbortedError` always bubble up unconditionally.
@@ -503,7 +538,7 @@ Use these method groups as the compact AxAgent surface map:
503
538
 
504
539
  - Running: `forward(ai, values, options?)` and `streamingForward(ai, values, options?)`.
505
540
  - Forward-time agent options: `skills`, `onUsedMemories`, and `onUsedSkills`; use `ax-agent-memory-skills` for details.
506
- - State and control: `getState()`, `setState(state?)`, `stop()`, `getSignature()`, `setSignature(signature)`, `getFunction()`, `getId()`, and `setId(id)`.
541
+ - State and control: `getState()`, `setState(state?)`, `getContextMap()`, `setContextMap(map?)`, `stop()`, `getSignature()`, `setSignature(signature)`, `getFunction()`, `getId()`, and `setId(id)`. Context-map evolve policy lives on `AxAgentContextMap` (`infiniteEvolve`, `evolveSteps`, `maxChars`), not on the agent config. See [`src/examples/rlm-context-map.ts`](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-context-map.ts) for persistence and finite-evolve usage.
507
542
  - Observability: `getChatLog()`, `getUsage()`, `getStagedUsage()`, `resetUsage()`, and `getTraces()`; use `ax-agent-observability` for details.
508
543
  - Demos and tuning: `setDemos(...)`, `namedPrograms()`, `namedProgramInstances()`, `optimize(...)`, `applyOptimization(...)`, `getOptimizableComponents()`, and `applyOptimizedComponents(...)`; use `ax-agent-optimize` for tuning details.
509
544
 
@@ -516,7 +551,7 @@ Rules:
516
551
 
517
552
  ## Tuning Hand-off
518
553
 
519
- When the user wants `agent.optimize(...)`, judge configuration, eval datasets, saved optimization artifacts, or recursive optimization guidance, use `ax-agent-optimize`.
554
+ When the user wants `agent.optimize(...)`, judge configuration, eval datasets, saved optimization artifacts, or optimization guidance, use `ax-agent-optimize`.
520
555
 
521
556
  Keep this skill focused on building and running agents. For tuning work:
522
557
 
package/skills/ax-ai.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-ai
3
- description: This skill helps an LLM generate correct AI provider setup and configuration code using @ax-llm/ax. Use when the user asks about ai(), providers, models, presets, embeddings, extended thinking, context caching, or mentions OpenAI/Anthropic/Google/Azure/Groq/DeepSeek/Mistral/Cohere/Together/Ollama/HuggingFace/Reka/OpenRouter with @ax-llm/ax.
4
- version: "21.0.12"
3
+ description: This skill helps an LLM generate correct AI provider setup and configuration code using @ax-llm/ax. Use when the user asks about ai(), providers, models, presets, embeddings, batch audio with ai.transcribe() or ai.speak(), extended thinking, context caching, or mentions OpenAI/Anthropic/Google/Azure/Groq/DeepSeek/Mistral/Cohere/Together/Ollama/HuggingFace/Reka/OpenRouter with @ax-llm/ax.
4
+ version: "21.0.13"
5
5
  ---
6
6
 
7
7
  # AI Provider Codegen Rules (@ax-llm/ax)
@@ -78,6 +78,30 @@ const res = await llm.chat({
78
78
  console.log(res.results[0]?.content);
79
79
  ```
80
80
 
81
+ ## Batch Audio
82
+
83
+ Use `ai.transcribe(...)` for batch speech-to-text and `ai.speak(...)` for batch text-to-speech. These are separate from conversational `.chat()` audio config.
84
+
85
+ ```typescript
86
+ const transcript = await llm.transcribe({
87
+ audio: { data: base64Wav, format: 'wav' },
88
+ model: 'gpt-4o-mini-transcribe',
89
+ language: 'en',
90
+ });
91
+
92
+ const speech = await llm.speak({
93
+ text: transcript.text,
94
+ model: 'gpt-4o-mini-tts',
95
+ voice: 'alloy',
96
+ format: 'mp3',
97
+ });
98
+
99
+ console.log(transcript.text);
100
+ console.log(speech.data);
101
+ ```
102
+
103
+ Providers without the requested audio endpoint throw `AxMediaNotSupportedError`. Use `speech` forward options for signature audio artifacts and `modelConfig.audio` for conversational chat audio.
104
+
81
105
  ## Common Options
82
106
 
83
107
  - `stream` (boolean): enable SSE; true by default
@@ -117,14 +141,21 @@ import { ai, AxAIDeepSeekModel } from '@ax-llm/ax';
117
141
  const deepseek = ai({
118
142
  name: 'deepseek',
119
143
  apiKey: process.env.DEEPSEEK_APIKEY!,
120
- config: { model: AxAIDeepSeekModel.DeepSeekV4Pro },
144
+ config: { model: AxAIDeepSeekModel.DeepSeekV4Flash },
121
145
  });
122
146
  ```
123
147
 
124
- DeepSeek V4 thinking models support tools, but reject the `tool_choice`
125
- request parameter. Ax omits forced/auto tool choice for `deepseek-v4-pro`,
126
- `deepseek-v4-flash`, and `deepseek-reasoner` while still sending tool
127
- definitions.
148
+ DeepSeek's current API models are `deepseek-v4-flash` and `deepseek-v4-pro`.
149
+ The deprecated `deepseek-chat` and `deepseek-reasoner` aliases are retained for
150
+ compatibility until DeepSeek removes them on 2026-07-24.
151
+
152
+ DeepSeek V4 supports thinking mode. Ax sends `thinking: { type: "disabled" }`
153
+ by default to preserve non-thinking behavior, and enables it when
154
+ `thinkingTokenBudget` is set. Ax maps lower budget levels to DeepSeek's `high`
155
+ effort and maps `highest` to `max`. DeepSeek V4 thinking models support tools,
156
+ but reject the `tool_choice` request parameter, so Ax omits forced/auto tool
157
+ choice for `deepseek-v4-pro`, `deepseek-v4-flash`, and `deepseek-reasoner`
158
+ while still sending tool definitions.
128
159
 
129
160
  ## Extended Thinking
130
161