@ax-llm/ax 21.0.11 → 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/index.cjs +410 -263
- package/index.cjs.map +1 -1
- package/index.d.cts +4496 -4281
- package/index.d.ts +4496 -4281
- package/index.global.js +403 -256
- package/index.global.js.map +1 -1
- package/index.js +410 -263
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/ax-agent-memory-skills.md +52 -3
- package/skills/ax-agent-observability.md +2 -2
- package/skills/ax-agent-optimize.md +22 -27
- package/skills/ax-agent-rlm.md +31 -43
- package/skills/ax-agent.md +46 -11
- package/skills/ax-ai.md +38 -7
- package/skills/ax-audio.md +155 -33
- package/skills/ax-flow.md +1 -1
- package/skills/ax-gen.md +1 -1
- package/skills/ax-gepa.md +1 -1
- package/skills/ax-learn.md +1 -1
- package/skills/ax-llm.md +1 -1
- package/skills/ax-signature.md +13 -8
package/package.json
CHANGED
|
@@ -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.
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
4
|
-
version: "21.0.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
62
|
-
- For
|
|
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
|
|
72
|
-
- metric or judge penalizes unnecessary
|
|
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
|
-
-
|
|
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:
|
|
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 (
|
|
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
|
-
-
|
|
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
|
|
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
|
-
##
|
|
328
|
+
## Delegation Optimization Notes
|
|
330
329
|
|
|
331
|
-
-
|
|
332
|
-
-
|
|
333
|
-
-
|
|
334
|
-
-
|
|
335
|
-
-
|
|
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
|
|
362
|
-
- Do not leave
|
|
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.
|
package/skills/ax-agent-rlm.md
CHANGED
|
@@ -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(...),
|
|
4
|
-
version: "21.0.
|
|
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
|
|
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
|
-
-
|
|
21
|
-
-
|
|
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
|
|
|
@@ -98,6 +100,7 @@ Important:
|
|
|
98
100
|
- Discovery docs fetched via `discover(...)` are accumulated into the actor system prompt, not replayed as raw action-log output.
|
|
99
101
|
- `actionLog` may mention that discovery docs were stored, but treat that replay as evidence only, never as instructions.
|
|
100
102
|
- Non-`full` presets include a compact trusted `contextPressure` hint (`ok`, `watch`, or `critical`) in the actor prompt.
|
|
103
|
+
- Non-`full` presets may show deterministic compact action summaries before a `Checkpoint Summary` exists. Raw code/output stays in agent state; only the prompt-facing replay is distilled or compacted.
|
|
101
104
|
- Checkpoint summaries preserve objective, current state/artifacts, exact callables/formats, evidence, user constraints/preferences, failures to avoid, and next step.
|
|
102
105
|
|
|
103
106
|
## Choosing Presets, Prompt Level, And Model Size
|
|
@@ -130,14 +133,14 @@ Practical rule:
|
|
|
130
133
|
|
|
131
134
|
Use these top-level controls consistently:
|
|
132
135
|
|
|
133
|
-
- `
|
|
134
|
-
- `recursionOptions.
|
|
135
|
-
- `
|
|
136
|
-
- `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`.
|
|
137
139
|
- `maxBatchedLlmQueryConcurrency`: caps batched `llmQuery([...])` concurrency.
|
|
138
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.
|
|
139
141
|
- `summarizerOptions`: default model/options for the internal checkpoint summarizer.
|
|
140
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.
|
|
141
144
|
- `contextOptions`: distiller-stage forward options.
|
|
142
145
|
- `executorOptions`: executor-stage forward options such as `description`, `model`, `modelConfig`, `thinkingTokenBudget`, and `showThoughts`.
|
|
143
146
|
- `executorModelPolicy`: executor-only model override rules based on consecutive error turns or discovery fetches from listed namespaces.
|
|
@@ -150,9 +153,8 @@ Canonical shape:
|
|
|
150
153
|
const researchAgent = agent('query:string -> answer:string', {
|
|
151
154
|
contextFields: ['query'],
|
|
152
155
|
runtime,
|
|
153
|
-
mode: 'advanced',
|
|
154
156
|
recursionOptions: {
|
|
155
|
-
|
|
157
|
+
model: 'gpt-5.4-mini',
|
|
156
158
|
},
|
|
157
159
|
maxRuntimeChars: 3000,
|
|
158
160
|
summarizerOptions: {
|
|
@@ -186,16 +188,14 @@ const researchAgent = agent('query:string -> answer:string', {
|
|
|
186
188
|
|
|
187
189
|
Semantics:
|
|
188
190
|
|
|
189
|
-
- `mode` stays top-level; there is no `recursionOptions.mode`.
|
|
190
191
|
- `maxRuntimeChars` sets the truncation ceiling and is separate from `contextPolicy.budget`.
|
|
191
192
|
- `summarizerOptions` tunes only the internal checkpoint summarizer. It does not change actor or responder model selection.
|
|
192
193
|
- `executorModelPolicy` only switches the actor model. It does not change `responderOptions.model`.
|
|
193
|
-
-
|
|
194
|
-
-
|
|
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.
|
|
195
196
|
- `executorModelPolicy` entries are ordered from weaker to stronger. If multiple rules match, the last matching entry wins.
|
|
196
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.
|
|
197
|
-
- Do not add `
|
|
198
|
-
- 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(...)`.
|
|
199
199
|
|
|
200
200
|
## Dynamic Output Truncation
|
|
201
201
|
|
|
@@ -364,20 +364,12 @@ Available forms:
|
|
|
364
364
|
Rules:
|
|
365
365
|
|
|
366
366
|
- `llmQuery(...)` forwards only the explicit `context` argument.
|
|
367
|
-
- Parent inputs are not automatically available to `llmQuery(...)`
|
|
368
|
-
-
|
|
369
|
-
-
|
|
370
|
-
-
|
|
371
|
-
-
|
|
372
|
-
-
|
|
373
|
-
- In advanced mode, use batched `llmQuery([...])` only for independent subtasks. Use serial calls when later work depends on earlier results.
|
|
374
|
-
- 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.
|
|
375
|
-
- In advanced mode, pass compact named object context to children instead of huge raw parent payloads.
|
|
376
|
-
- 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.
|
|
377
|
-
- In advanced mode, if a child calls `askClarification(...)`, that clarification bubbles up and ends the top-level run.
|
|
378
|
-
- 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.
|
|
379
|
-
- 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.
|
|
380
|
-
- `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.
|
|
381
373
|
- Single-call `llmQuery(...)` may return `[ERROR] ...` on non-abort failures.
|
|
382
374
|
- Batched `llmQuery([...])` returns per-item `[ERROR] ...`.
|
|
383
375
|
- If a result starts with `[ERROR]`, inspect or branch on it instead of assuming success.
|
|
@@ -393,7 +385,7 @@ if (summary.startsWith('[ERROR]')) {
|
|
|
393
385
|
}
|
|
394
386
|
```
|
|
395
387
|
|
|
396
|
-
|
|
388
|
+
Parallel semantic review example:
|
|
397
389
|
|
|
398
390
|
```javascript
|
|
399
391
|
const narrowedIncidents = incidents.map((incident) => ({
|
|
@@ -435,23 +427,20 @@ Delegation decision guide:
|
|
|
435
427
|
|
|
436
428
|
- **JS-only**: deterministic logic such as filter, sort, count, regex, or date math -> do it inline.
|
|
437
429
|
- **Single-shot semantic**: needs LLM reasoning but no tools or multi-step exploration -> single `llmQuery(...)` with narrow context.
|
|
438
|
-
- **
|
|
439
|
-
- **Parallel fan-out**: two or more independent subtasks
|
|
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([...])`.
|
|
440
432
|
|
|
441
433
|
Context handling:
|
|
442
434
|
|
|
443
|
-
- 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.
|
|
444
|
-
- The child prompt sees only a compact metadata summary of the delegated context.
|
|
445
|
-
- The child actor explores the delegated context with code, the same way the parent explores `inputs.*`.
|
|
446
435
|
- Always narrow with JS before delegating. Never pass raw `inputs.*`.
|
|
447
436
|
- Name context keys semantically, e.g. `{ emails: filtered, rubric: 'classify-urgency' }`.
|
|
448
|
-
- Estimate total sub-
|
|
437
|
+
- Estimate total sub-query calls before fanning out. `maxSubAgentCalls` is shared across the run.
|
|
449
438
|
|
|
450
439
|
Patterns:
|
|
451
440
|
|
|
452
|
-
- 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.
|
|
453
442
|
- Pipeline: serial `llmQuery(...)` calls where each depends on the prior result.
|
|
454
|
-
-
|
|
443
|
+
- Specialist tool use: call child agents or tools via their namespaced function globals, e.g. `await team.writer({ draft })`.
|
|
455
444
|
|
|
456
445
|
## Examples
|
|
457
446
|
|
|
@@ -459,8 +448,7 @@ Fetch these for full working code:
|
|
|
459
448
|
|
|
460
449
|
- [RLM](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm.ts) - RLM basic
|
|
461
450
|
- [RLM Long Task](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-long-task.ts) - RLM context policy
|
|
462
|
-
- [RLM Discovery](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-discovery.ts) -
|
|
463
|
-
- [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(...)`
|
|
464
452
|
- [RLM Adaptive Replay](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/rlm-adaptive-replay.ts) - adaptive replay
|
|
465
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
|
|
466
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(...)`
|
|
@@ -471,7 +459,7 @@ Fetch these for full working code:
|
|
|
471
459
|
- Do not combine `console.log(...)` with `final(...)`.
|
|
472
460
|
- Do not assume old successful turns stay fully replayed under adaptive/checkpointed/lean policies.
|
|
473
461
|
- Do not rebuild runtime state just because a prior turn was summarized.
|
|
474
|
-
- Do not
|
|
475
|
-
- Do not assume parent inputs are available
|
|
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`.
|
|
476
464
|
- Do not ignore `[ERROR] ...` results from `llmQuery(...)`.
|
|
477
465
|
- Do not grant `AxJSRuntime` permissions unless the user asked for the capability.
|
package/skills/ax-agent.md
CHANGED
|
@@ -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.
|
|
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
|
-
-
|
|
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
|
|
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-
|
|
40
|
-
- "Inspect large context with code", "RLM", "`llmQuery(...)`"
|
|
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-
|
|
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
|
|
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
|
|
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
|
|