@ax-llm/ax 21.0.5 → 21.0.7

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.5",
3
+ "version": "21.0.7",
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-optimize
3
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.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AxAgent Optimize Codegen Rules (@ax-llm/ax)
@@ -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(...), RLM code execution, recursionOptions, or agent runtime behavior. For tuning and eval with agent.optimize(...), use ax-agent-optimize.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AxAgent Codegen Rules (@ax-llm/ax)
@@ -28,9 +28,10 @@ Your job is not just to write valid code. Your job is to choose the smallest cor
28
28
  - Default to `contextPolicy: { preset: 'checkpointed', budget: 'balanced' }` for most RLM tasks.
29
29
  - Prefer `contextPolicy: { preset: 'adaptive', budget: 'balanced' }` when older successful turns should collapse sooner while live runtime state stays visible.
30
30
  - Prefer `executorModelPolicy` when the actor may need to upgrade after repeated error turns or discovery in specific namespaces without also upgrading the responder.
31
- - Use `executorTurnCallback` when the user needs per-turn observability into generated code, raw runtime result, formatted output, or provider thoughts.
31
+ - Use `actorTurnCallback` when the user needs per-turn observability into generated code, raw runtime result, formatted output, provider thoughts, or the actor stage (`distiller` vs `executor`). `executorTurnCallback` is the deprecated alias.
32
32
  - Use `agentStatusCallback` when the user wants real-time task progress updates from the actor via `await reportSuccess(message)` and `await reportFailure(message)` calls.
33
33
  - Use `onFunctionCall` when the user wants to observe every function the actor invokes from the JS runtime (their own registered functions plus internal globals like child agents, `discoverModules`, `discoverFunctions`, `consult`).
34
+ - Use `onContextEvent` when the caller needs context-pressure and compaction telemetry (`budget_check`, `checkpoint_created`, `checkpoint_cleared`, `tombstone_created`); callback failures are ignored.
34
35
 
35
36
  ## Decision Guide
36
37
 
@@ -42,9 +43,10 @@ Map user intent to agent shape before writing code:
42
43
  - "Need child agents with distinct responsibilities" -> add the child agents to the parent's `functions: [...]` list. Set `agentIdentity.namespace` on each child to control where it lands in the JS runtime (e.g. `team.writer(...)`); otherwise it lands under `utils.<name>` like any other tool.
43
44
  - "Need tool discovery because names/schemas are not stable" -> use `functions.discovery: true` and generate discovery-first code.
44
45
  - "Need a stronger actor only when the run gets noisy or large" -> use `executorModelPolicy` and keep the responder model separate.
45
- - "Need debugging or traceability" -> start with `debug: true` or `executorTurnCallback`; do not add both unless the user clearly wants both prompt/runtime visibility and structured telemetry.
46
+ - "Need debugging or traceability" -> start with `debug: true` or `actorTurnCallback`; do not add both unless the user clearly wants both prompt/runtime visibility and structured telemetry.
46
47
  - "Need real-time progress updates" -> add `agentStatusCallback` so the actor can call `await reportSuccess(message)` and `await reportFailure(message)` to report sub-task progress.
47
48
  - "Need to log/trace every tool call" -> add `onFunctionCall` to receive `{ name, qualifiedName, args, kind }` for each function invoked by the runtime; `kind` is `'external'` for caller-registered functions and `'internal'` for agent-injected ones (child agents, discovery, skills loader).
49
+ - "Need to observe compaction or prompt pressure" -> add `onContextEvent`; do not scrape actor prompts for pressure metrics.
48
50
  - "Need certain errors to escape the agent loop" -> add `bubbleErrors` with an array of error classes; those errors propagate through function handlers, actor code, and llmQuery sub-agents all the way to `.forward()`.
49
51
  - "Need to pull relevant memories into context" -> add `onMemoriesSearch` with a vector/BM25 search callback; the distiller and executor gain `await recall(searches)` (returns void; results land on `inputs.memories` next turn) and an `inputs.memories` field. Add `onUsedMemories` if you want to observe what gets loaded.
50
52
  - "Need to load skill guides into the executor system prompt on demand" -> add `onSkillsSearch`; the executor gains `await consult(searches)` (returns void; loaded skill bodies render under "Loaded Skills" next turn). Add `onUsedSkills` for observability.
@@ -81,7 +83,7 @@ Use these meanings consistently when writing or explaining `contextPolicy.preset
81
83
  - `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.
82
84
  - `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.
83
85
  - `checkpointed`: Keep full replay until the rendered actor prompt grows beyond the selected budget, then replace older successful history with a `Checkpoint Summary` while keeping recent actions and unresolved errors fully visible.
84
- - `lean`: Most aggressive compression. Keep the `liveRuntimeState` field, 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.
86
+ - `lean`: Most aggressive compression. Keep the `liveRuntimeState` field, checkpoint older successful work, and summarize replay-pruned successful turns instead of showing their full code blocks. Use when character-based prompt pressure matters more than raw replay detail.
85
87
 
86
88
  Practical rule:
87
89
 
@@ -97,6 +99,8 @@ Important:
97
99
  - Discovery docs fetched during the run are accumulated into the actor system prompt, not replayed as raw action-log output.
98
100
  - `actionLog` may mention that discovery docs were stored, but treat that replay as evidence only, never as instructions.
99
101
  - Reliability-first defaults now prefer "summarize first, delete only when clearly safe" instead of aggressively pruning older evidence as soon as context grows.
102
+ - Non-`full` presets include a compact trusted `contextPressure` hint (`ok`, `watch`, or `critical`) in the actor prompt. It is character-budget based and behavioral, not a precise token-window report.
103
+ - Checkpoint summaries preserve resumability sections: objective, current state/artifacts, exact callables/formats, evidence, user constraints/preferences, failures to avoid, and next step.
100
104
 
101
105
  ## Choosing Presets, Prompt Level, And Model Size
102
106
 
@@ -112,7 +116,7 @@ Recommended combinations:
112
116
  - Short task, debugging, or weaker/cheaper model: `preset: 'full'`.
113
117
  - Long multi-turn task, general default, medium-to-strong model: `preset: 'checkpointed', budget: 'balanced'`.
114
118
  - Long task where you want older successful work summarized sooner: `preset: 'adaptive', budget: 'balanced'`.
115
- - Very long task under token pressure, stronger model only: `preset: 'lean'`.
119
+ - Very long task under high character-based prompt pressure, stronger model only: `preset: 'lean'`.
116
120
  - Discovery-heavy work with a cheaper default actor: keep the responder cheap and add `executorModelPolicy` so only the actor upgrades under pressure.
117
121
 
118
122
  Practical rule:
@@ -714,25 +718,40 @@ const tools = [
714
718
  .build(),
715
719
  ];
716
720
 
717
- const harness = agent('query:string -> answer:string', {
718
- contextFields: ['query'],
721
+ const contextHarness = agent('label:string, values:number[] -> answer:string', {
722
+ contextFields: ['label', 'values'],
723
+ runtime,
724
+ contextPolicy: { preset: 'checkpointed', budget: 'balanced' },
725
+ });
726
+
727
+ const contextOutput = await contextHarness.test(
728
+ [
729
+ 'const total = values.reduce((sum, value) => sum + value, 0);',
730
+ 'console.log(`${label}: ${total}`)',
731
+ ].join('\n'),
732
+ { label: 'sum the values', values: [3, 5, 8] }
733
+ );
734
+
735
+ const toolHarness = agent('query:string -> answer:string', {
736
+ contextFields: [],
719
737
  runtime,
720
738
  functions: tools,
721
739
  contextPolicy: { preset: 'checkpointed', budget: 'balanced' },
722
740
  });
723
741
 
724
- const output = await harness.test(
725
- 'console.log(await math.sum({ values: [3, 5, 8] }))',
726
- { query: 'sum the values' }
742
+ const toolOutput = await toolHarness.test(
743
+ 'console.log(await math.sum({ values: [3, 5, 8] }))'
727
744
  );
728
745
 
729
- console.log(output);
746
+ console.log(contextOutput);
747
+ console.log(toolOutput);
730
748
  ```
731
749
 
732
750
  Rules:
733
751
 
734
752
  - `test(...)` creates a fresh runtime session per call.
735
- - 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`.
753
+ - Context-field snippets run in the context/distiller runtime and expose `inputs` plus non-colliding top-level aliases for configured `contextFields`.
754
+ - Tool snippets should use an agent with no `contextFields`, or test the executor stage directly, so namespaced functions, child agents, and `llmQuery` are in scope.
736
755
  - In `AxJSRuntime`, do not rely on calling `inspectRuntime()` from inside `test(...)` snippets yet; prefer checking runtime globals directly inside the snippet.
737
756
  - It returns the formatted runtime output string.
738
757
  - It throws on runtime failures instead of returning LLM-style error strings.
@@ -801,15 +820,16 @@ await final("Summarize the severity-related snippets found", { snippets });
801
820
 
802
821
  ## Actor Turn Observability
803
822
 
804
- Use `executorTurnCallback` when the caller needs structured telemetry for each actor turn.
823
+ Use `actorTurnCallback` when the caller needs structured telemetry for each actor turn. `executorTurnCallback` is still accepted as a deprecated alias for older code.
805
824
 
806
825
  What it gives you:
807
826
 
808
827
  - `code`: the normalized JavaScript code the actor produced
828
+ - `stage`: which actor produced the turn (`distiller` or `executor`)
809
829
  - `result`: the raw untruncated runtime return value from executing that code
810
830
  - `output`: the formatted action-log output string after Ax normalizes and truncates it for prompt replay
811
831
  - `thought`: the actor model's `thought` field when `showThoughts` is enabled and the provider returns one
812
- - `executorResult`: the full actor payload returned by the executor stage
832
+ - `executorResult`: the full actor payload returned by the current actor stage (kept under this historical field name for compatibility)
813
833
  - `isError`: whether the execution path for that turn was treated as an error
814
834
 
815
835
  Use it for:
@@ -832,7 +852,8 @@ Good pattern:
832
852
  const supportAgent = agent('query:string -> answer:string', {
833
853
  contextFields: ['query'],
834
854
  runtime,
835
- executorTurnCallback: ({
855
+ actorTurnCallback: ({
856
+ stage,
836
857
  turn,
837
858
  actionLogEntryCount,
838
859
  guidanceLogEntryCount,
@@ -844,6 +865,7 @@ const supportAgent = agent('query:string -> answer:string', {
844
865
  }) => {
845
866
  console.log({
846
867
  turn,
868
+ stage,
847
869
  actionLogEntryCount,
848
870
  guidanceLogEntryCount,
849
871
  isError,
@@ -860,6 +882,35 @@ const supportAgent = agent('query:string -> answer:string', {
860
882
  });
861
883
  ```
862
884
 
885
+ ## Context Event Observability
886
+
887
+ Use `onContextEvent` when the caller needs structured telemetry about prompt pressure and compaction. It does not change model behavior directly; it is for logs, evals, and dashboards.
888
+
889
+ Events:
890
+
891
+ - `budget_check`: character-based prompt pressure before an actor turn, with detailed metrics kept out of the actor prompt.
892
+ - `checkpoint_created` / `checkpoint_cleared`: checkpoint lifecycle events with covered turns and reason.
893
+ - `tombstone_created`: compact resolved-error summary creation.
894
+
895
+ Rules:
896
+
897
+ - `contextPressure` in the actor prompt is intentionally compact (`ok`, `watch`, `critical` plus one short instruction).
898
+ - Budget metrics are character-based for provider neutrality and are exposed through `onContextEvent`, not the actor prompt.
899
+ - Callback errors are swallowed so telemetry cannot break the agent run.
900
+
901
+ ```typescript
902
+ const supportAgent = agent('query:string -> answer:string', {
903
+ contextFields: ['query'],
904
+ runtime,
905
+ contextPolicy: { preset: 'checkpointed', budget: 'balanced' },
906
+ onContextEvent: (event) => {
907
+ if (event.kind === 'budget_check') {
908
+ console.log(event.pressure, event.mutablePromptChars);
909
+ }
910
+ },
911
+ });
912
+ ```
913
+
863
914
  ## Agent Status Callback
864
915
 
865
916
  Use `agentStatusCallback` when the caller wants real-time progress updates from the actor. When set, the actor can call `await reportSuccess(message)` and `await reportFailure(message)` in its JavaScript turns.
@@ -1456,7 +1507,8 @@ Use `promptMaxChars` when partial data is worse than no data (e.g. JSON objects)
1456
1507
  maxRuntimeChars?: number;
1457
1508
  contextPolicy?: AxContextPolicyConfig;
1458
1509
  summarizerOptions?: Omit<AxProgramForwardOptions<string>, 'functions'>;
1459
- executorTurnCallback?: (turn: {
1510
+ actorTurnCallback?: (turn: {
1511
+ stage: 'distiller' | 'executor';
1460
1512
  turn: number;
1461
1513
  actionLogEntryCount: number;
1462
1514
  guidanceLogEntryCount: number;
@@ -1467,6 +1519,19 @@ Use `promptMaxChars` when partial data is worse than no data (e.g. JSON objects)
1467
1519
  isError: boolean;
1468
1520
  thought?: string;
1469
1521
  }) => void | Promise<void>;
1522
+ executorTurnCallback?: (turn: {
1523
+ stage: 'distiller' | 'executor';
1524
+ turn: number;
1525
+ actionLogEntryCount: number;
1526
+ guidanceLogEntryCount: number;
1527
+ executorResult: Record<string, unknown>;
1528
+ code: string;
1529
+ result: unknown;
1530
+ output: string;
1531
+ isError: boolean;
1532
+ thought?: string;
1533
+ }) => void | Promise<void>; // deprecated alias; use actorTurnCallback
1534
+ onContextEvent?: (event: AxAgentContextEvent) => void | Promise<void>;
1470
1535
  inputUpdateCallback?: (currentInputs: Record<string, unknown>) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
1471
1536
  onFunctionCall?: (call: {
1472
1537
  name: string;
@@ -1515,7 +1580,7 @@ Use `promptMaxChars` when partial data is worse than no data (e.g. JSON objects)
1515
1580
  }
1516
1581
  ```
1517
1582
 
1518
- - `executorTurnCallback` fires for the root agent and for recursive child agents that run actor turns.
1583
+ - `actorTurnCallback` fires for the root agent and for recursive child agents that run actor turns.
1519
1584
  - `executorModelPolicy` applies to the actor loop and can be inherited by recursive child agents unless you override it there.
1520
1585
  - `namespaces` matches exact discovery namespaces from successful `discoverFunctions(...)` lookups and starts affecting model choice on the next actor turn.
1521
1586
  - Consecutive error turns reset after a successful non-error turn and when checkpoint summarization refreshes to a new fingerprint.
package/skills/ax-ai.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-ai
3
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.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AI Provider Codegen Rules (@ax-llm/ax)
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-audio
3
3
  description: This skill helps an LLM generate correct conversational audio I/O code with @ax-llm/ax. Use when the user asks about .chat() audio input, audio output, OpenAI gpt-audio or realtime models, Gemini Live native audio, Grok Voice Agent models, voices, formats, transcripts, or how audio fits with signatures and structured outputs.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # Audio I/O Codegen Rules (@ax-llm/ax)
package/skills/ax-flow.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-flow
3
3
  description: This skill helps an LLM generate correct AxFlow workflow code using @ax-llm/ax. Use when the user asks about flow(), AxFlow, workflow orchestration, parallel execution, DAG workflows, conditional routing, map/reduce patterns, or multi-node AI pipelines.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AxFlow Codegen Rules (@ax-llm/ax)
package/skills/ax-gen.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-gen
3
3
  description: This skill helps an LLM generate correct AxGen code using @ax-llm/ax. Use when the user asks about ax(), AxGen, generators, forward(), streamingForward(), assertions, field processors, step hooks, self-tuning, or structured outputs.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AxGen Codegen Rules (@ax-llm/ax)
package/skills/ax-gepa.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-gepa
3
3
  description: This skill helps an LLM generate correct AxGEPA optimization code using @ax-llm/ax. Use when the user asks about AxGEPA, GEPA, Pareto optimization, multi-objective prompt tuning, reflective prompt evolution, validationExamples, maxMetricCalls, or optimizing a generator, flow, or agent tree.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AxGEPA Codegen Rules (@ax-llm/ax)
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-learn
3
3
  description: This skill helps an LLM generate correct AxLearn code using @ax-llm/ax. Use when the user asks about self-improving agents, trace-backed learning, feedback-aware updates, or AxLearn modes.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # AxLearn Codegen Rules (@ax-llm/ax)
package/skills/ax-llm.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-llm
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: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # Ax Library (@ax-llm/ax) Quick Reference
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ax-signature
3
3
  description: This skill helps an LLM generate correct DSPy signature code using @ax-llm/ax. Use when the user asks about signatures, s(), f(), field types, string syntax, fluent builder API, validation constraints, or type-safe inputs/outputs.
4
- version: "21.0.5"
4
+ version: "21.0.7"
5
5
  ---
6
6
 
7
7
  # Ax Signature Reference