@ax-llm/ax 19.0.15 → 19.0.16

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": "19.0.15",
3
+ "version": "19.0.16",
4
4
  "type": "module",
5
5
  "description": "The best library to work with LLMs",
6
6
  "repository": {
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-agent
3
3
  description: This skill helps an LLM generate correct AxAgent code using @ax-llm/ax. Use when the user asks about agent(), child agents, namespaced functions, discovery mode, shared fields, llmQuery(...), or RLM code execution.
4
- version: "19.0.15"
4
+ version: "19.0.16"
5
5
  ---
6
6
 
7
7
  # AxAgent Codegen Rules (@ax-llm/ax)
@@ -11,11 +11,26 @@ Use this skill to generate `AxAgent` code. Prefer short, modern, copyable patter
11
11
  ## Use These Defaults
12
12
 
13
13
  - Use `agent(...)`, not `new AxAgent(...)`.
14
+ - Prefer `fn(...)` for host-side function definitions instead of hand-writing JSON Schema objects.
14
15
  - Prefer namespaced functions such as `utils.search(...)` or `kb.find(...)`.
15
16
  - Assume the child-agent module is `agents` unless `agentIdentity.namespace` is set.
16
17
  - If `functions.discovery` is `true`, discover callables from modules before using them.
17
18
  - In stdout-mode RLM, use one observable `console.log(...)` step per non-final actor turn.
18
- - For long RLM tasks, prefer `contextManagement.actionReplay: 'adaptive'` plus `stateSummary` so prior exploratory turns are summarized and live runtime state stays visible.
19
+ - For long RLM tasks, prefer `contextPolicy: { preset: 'adaptive' }` so older successful turns collapse into checkpoint summaries while live runtime state stays visible.
20
+
21
+ ## Context Policy Presets
22
+
23
+ Use these meanings consistently when writing or explaining `contextPolicy.preset`:
24
+
25
+ - `full`: Keep prior actions fully replayed. Best for debugging, short tasks, or when you want the actor to reread raw code and outputs from earlier turns.
26
+ - `adaptive`: Keep runtime state visible, keep recent or dependency-relevant actions in full, and collapse older successful work into a `Checkpoint Summary` when context grows. This is the default recommendation for long multi-turn tasks.
27
+ - `lean`: Most aggressive compression. Keep `Live Runtime State`, checkpoint older successful work, and summarize replay-pruned successful turns instead of showing their full code blocks. Use when token pressure matters more than raw replay detail.
28
+
29
+ Practical rule:
30
+
31
+ - Start with `adaptive` for most long RLM tasks.
32
+ - Use `lean` only when the task can mostly continue from current runtime state plus compact summaries.
33
+ - Use `full` when you are debugging the actor loop itself or need exact prior code/output in prompt.
19
34
 
20
35
  ## Critical Rules
21
36
 
@@ -24,10 +39,11 @@ Use this skill to generate `AxAgent` code. Prefer short, modern, copyable patter
24
39
  - If `functions.discovery` is `true`, call `listModuleFunctions(...)` first, then `getFunctionDefinitions(...)`, then call only discovered functions.
25
40
  - In stdout-mode RLM, non-final turns must emit exactly one `console.log(...)` and stop immediately after it.
26
41
  - Never combine `console.log(...)` with `final(...)` or `ask_clarification(...)` in the same actor turn.
42
+ - If a host-side `AxAgentFunction` needs to end the current actor turn, use `extra.protocol.final(...)` or `extra.protocol.askClarification(...)`.
27
43
  - If a child agent needs parent inputs such as `audience`, use `fields.shared` or `fields.globallyShared`.
28
44
  - `llmQuery(...)` failures may come back as `[ERROR] ...`; do not assume success.
29
- - If `contextManagement.stateSummary.enabled` is on, rely on the `Live Runtime State` block for current variables instead of re-reading old action log code.
30
- - If `contextManagement.actionReplay` is `'adaptive'` or `'minimal'`, assume older successful turns may be summarized or omitted.
45
+ - If `contextPolicy.state.summary` is on, rely on the `Live Runtime State` block for current variables instead of re-reading old action log code.
46
+ - If `contextPolicy.preset` is `'adaptive'` or `'lean'`, assume older successful turns may be replaced by a `Checkpoint Summary` and that replay-pruned successful turns may appear as compact summaries instead of full code blocks.
31
47
 
32
48
  ## Canonical Pattern
33
49
 
@@ -119,43 +135,34 @@ Rules:
119
135
  ## Tool Functions And Namespaces
120
136
 
121
137
  ```typescript
122
- import type { AxAgentFunction } from '@ax-llm/ax';
138
+ import { f, fn } from '@ax-llm/ax';
139
+
140
+ const tools = [
141
+ fn('findSnippets')
142
+ .description('Find handbook snippets by topic')
143
+ .namespace('kb')
144
+ .arg('topic', f.string('Topic keyword'))
145
+ .returns(f.string('Matching snippet').array())
146
+ .example({
147
+ title: 'Find severity guidance',
148
+ code: 'await kb.findSnippets({ topic: "severity" });',
149
+ })
150
+ .handler(async ({ topic }) => [])
151
+ .build(),
152
+ ];
123
153
 
124
- const tools: AxAgentFunction[] = [
125
- {
126
- name: 'findSnippets',
127
- namespace: 'kb',
128
- description: 'Find handbook snippets by topic',
129
- parameters: {
130
- type: 'object',
131
- properties: {
132
- topic: { type: 'string', description: 'Topic keyword' },
133
- },
134
- required: ['topic'],
135
- },
136
- returns: {
137
- type: 'array',
138
- items: { type: 'string' },
139
- },
140
- examples: [
154
+ const analyst = agent('query:string -> answer:string', {
155
+ functions: {
156
+ local: [
141
157
  {
142
- title: 'Find severity guidance',
143
- code: 'await kb.findSnippets({ topic: "severity" });',
158
+ namespace: 'kb',
159
+ title: 'Knowledge Base',
160
+ selectionCriteria: 'Use for handbook and documentation lookups.',
161
+ description: 'Handbook and documentation search helpers.',
162
+ functions: tools.map(({ namespace: _namespace, ...tool }) => tool),
144
163
  },
145
164
  ],
146
- func: async ({ topic }) => [],
147
165
  },
148
- ];
149
-
150
- const analyst = agent('query:string -> answer:string', {
151
- namespaces: [
152
- {
153
- name: 'kb',
154
- title: 'Knowledge Base',
155
- description: 'Handbook and documentation search helpers.',
156
- },
157
- ],
158
- functions: { local: tools },
159
166
  contextFields: [],
160
167
  });
161
168
  ```
@@ -172,6 +179,44 @@ Rules:
172
179
  - Default function namespace is `utils` when no namespace is set.
173
180
  - Use the runtime call shape `await <namespace>.<name>({...})`.
174
181
 
182
+ ## Host-Side Completion From Functions
183
+
184
+ Use this pattern when the actor should call a namespaced function, but the host-side function implementation should decide to end the turn:
185
+
186
+ ```typescript
187
+ import { f, fn } from '@ax-llm/ax';
188
+
189
+ const workflowTools = [
190
+ fn('finishReply')
191
+ .description('Complete the actor turn with the final reply text')
192
+ .namespace('workflow')
193
+ .arg('reply', f.string('Final reply text'))
194
+ .returns(f.string('Final reply text'))
195
+ .handler(async ({ reply }, extra) => {
196
+ extra?.protocol?.final(reply);
197
+ return reply;
198
+ })
199
+ .build(),
200
+ fn('askForOrderId')
201
+ .description('Complete the actor turn by requesting clarification')
202
+ .namespace('workflow')
203
+ .arg('question', f.string('Clarification question'))
204
+ .returns(f.string('Clarification question'))
205
+ .handler(async ({ question }, extra) => {
206
+ extra?.protocol?.askClarification(question);
207
+ return question;
208
+ })
209
+ .build(),
210
+ ];
211
+ ```
212
+
213
+ Rules:
214
+
215
+ - `extra.protocol` is only available when the function call comes from an active AxAgent actor runtime session.
216
+ - Use `extra.protocol.final(...)` or `extra.protocol.askClarification(...)` only inside host-side function handlers.
217
+ - Inside actor-authored JavaScript, keep using the runtime globals `final(...)` and `ask_clarification(...)`.
218
+ - Do not model these protocol completions as normal registered tool functions or discovery entries.
219
+
175
220
  ## Discovery Mode
176
221
 
177
222
  Enable discovery mode when you want the actor to discover modules and fetch callable definitions on demand:
@@ -199,7 +244,8 @@ Discovery APIs:
199
244
 
200
245
  Both return Markdown.
201
246
 
202
- - `listModuleFunctions(...)` only lists modules that actually have callable entries. Namespace metadata from `namespaces` only enriches those callable-backed modules.
247
+ - `listModuleFunctions(...)` only lists modules that actually have callable entries.
248
+ - Grouped modules render in the Actor prompt as `<namespace> - <selection criteria>` when criteria is provided.
203
249
  - If a requested module does not exist, `listModuleFunctions(...)` returns a per-module markdown error without failing the whole call.
204
250
  - `getFunctionDefinitions(...)` may include argument comments from schema descriptions and fenced code examples from `AxAgentFunction.examples`.
205
251
 
@@ -247,7 +293,54 @@ Use these rules when generating actor JavaScript for RLM in stdout mode:
247
293
  - Non-final turns should contain exactly one `console.log(...)`.
248
294
  - Final turns should call `final(...)` or `ask_clarification(...)` without `console.log(...)`.
249
295
  - Do not write a complete multi-step program in one actor turn.
250
- - Do not assume older successful turns remain fully replayed; adaptive replay may compress them to `[SUMMARY]: ...`.
296
+ - Do not assume older successful turns remain fully replayed; adaptive or lean policies may collapse them into a `Checkpoint Summary` block or compact action summaries.
297
+
298
+ ## RLM Test Harness
299
+
300
+ Use `agent.test(code, contextFieldValues?, options?)` when the user wants to validate JavaScript snippets against the actual AxAgent runtime environment without running the full Actor/Responder loop.
301
+
302
+ ```typescript
303
+ import { AxJSRuntime, agent, f, fn } from '@ax-llm/ax';
304
+
305
+ const runtime = new AxJSRuntime();
306
+
307
+ const tools = [
308
+ fn('sum')
309
+ .description('Return the sum of the provided numeric values')
310
+ .namespace('math')
311
+ .arg('values', f.number('Value to add').array())
312
+ .returns(f.number('Sum of all values'))
313
+ .handler(async ({ values }) =>
314
+ values.reduce((total, value) => total + value, 0)
315
+ )
316
+ .build(),
317
+ ];
318
+
319
+ const harness = agent('query:string -> answer:string', {
320
+ contextFields: ['query'],
321
+ runtime,
322
+ functions: { local: tools },
323
+ contextPolicy: { preset: 'adaptive' },
324
+ });
325
+
326
+ const output = await harness.test(
327
+ 'console.log(await math.sum({ values: [3, 5, 8] }))',
328
+ { query: 'sum the values' }
329
+ );
330
+
331
+ console.log(output);
332
+ ```
333
+
334
+ Rules:
335
+
336
+ - `test(...)` creates a fresh runtime session per call.
337
+ - It exposes the same runtime globals the actor would see for configured `contextFields`: `inputs`, non-colliding top-level aliases, namespaced functions, child agents, and `llmQuery`.
338
+ - In `AxJSRuntime`, do not rely on calling `inspect_runtime()` from inside `test(...)` snippets yet; prefer checking runtime globals directly inside the snippet.
339
+ - It returns the formatted runtime output string.
340
+ - It throws on runtime failures instead of returning LLM-style error strings.
341
+ - Do not call `final(...)` or `ask_clarification(...)` inside `test(...)` snippets.
342
+ - Pass only `contextFields` values to `test(...)`; it is not a general way to inject arbitrary non-context inputs.
343
+ - If the snippet uses `llmQuery(...)`, provide an AI service through the agent config or `options.ai`.
251
344
 
252
345
  ## RLM Adaptive Replay
253
346
 
@@ -260,15 +353,22 @@ const analyst = agent(
260
353
  contextFields: ['context'],
261
354
  runtime: new AxJSRuntime(),
262
355
  maxTurns: 10,
263
- contextManagement: {
264
- actionReplay: 'adaptive',
265
- recentFullActions: 1,
266
- successSummarization: true,
267
- stateSummary: { enabled: true, maxEntries: 6 },
268
- stateInspection: { contextThreshold: 2_000 },
269
- errorPruning: true,
270
- hindsightEvaluation: true,
271
- pruneRank: 2,
356
+ contextPolicy: {
357
+ preset: 'adaptive',
358
+ state: {
359
+ summary: true,
360
+ inspect: true,
361
+ inspectThresholdChars: 2_000,
362
+ maxEntries: 6,
363
+ },
364
+ checkpoints: {
365
+ enabled: true,
366
+ triggerChars: 2_000,
367
+ },
368
+ expert: {
369
+ pruneErrors: true,
370
+ rankPruning: { enabled: true, minRank: 2 },
371
+ },
272
372
  },
273
373
  }
274
374
  );
@@ -276,12 +376,11 @@ const analyst = agent(
276
376
 
277
377
  Rules:
278
378
 
279
- - Use `actionReplay: 'adaptive'` when the task needs runtime state across many turns but old exploratory code should not keep bloating the prompt.
280
- - Use `recentFullActions` to keep the newest one or two turns verbatim while older successful turns collapse to summaries.
281
- - Use `successSummarization: true` for explicit, compact summaries of older successful turns.
282
- - Use `stateSummary.enabled` to inject a compact `Live Runtime State` block into the actor prompt.
283
- - Use `actionReplay: 'minimal'` only when you want aggressively compressed history and can rely mostly on current runtime state.
284
- - Keep `stateInspection.contextThreshold` on so the actor is reminded to call `inspect_runtime()` when context grows.
379
+ - Use `preset: 'full'` when the actor should keep seeing raw prior code and outputs with minimal compression.
380
+ - Use `preset: 'adaptive'` when the task needs runtime state across many turns but older successful work should collapse into checkpoint summaries while important recent steps can still stay fully replayed.
381
+ - Use `preset: 'lean'` when you want more aggressive compression and can rely mostly on current runtime state plus checkpoint summaries and compact action summaries.
382
+ - Use `state.summary` to inject a compact `Live Runtime State` block into the actor prompt.
383
+ - Use `state.inspect` with `inspectThresholdChars` so the actor is reminded to call `inspect_runtime()` when context grows.
285
384
 
286
385
  Good pattern:
287
386
 
@@ -455,7 +554,7 @@ agentIdentity?: {
455
554
  maxRuntimeChars?: number;
456
555
  maxBatchedLlmQueryConcurrency?: number;
457
556
  maxTurns?: number;
458
- contextManagement?: AxContextManagementConfig;
557
+ contextPolicy?: AxContextPolicyConfig;
459
558
  actorFields?: string[];
460
559
  actorCallback?: (result: Record<string, unknown>) => void | Promise<void>;
461
560
  inputUpdateCallback?: (currentInputs: Record<string, unknown>) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
package/skills/ax-llm.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax
3
3
  description: This skill helps with using the @ax-llm/ax TypeScript library for building LLM applications. Use when the user asks about ax(), ai(), f(), s(), agent(), flow(), AxGen, AxAgent, AxFlow, signatures, streaming, or mentions @ax-llm/ax.
4
- version: "19.0.15"
4
+ version: "19.0.16"
5
5
  ---
6
6
 
7
7
  # Ax Library (@ax-llm/ax) Usage Guide