@ax-llm/ax 21.0.4 → 21.0.6

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.4",
3
+ "version": "21.0.6",
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
5
5
  ---
6
6
 
7
7
  # AxAgent Codegen Rules (@ax-llm/ax)
@@ -31,6 +31,7 @@ Your job is not just to write valid code. Your job is to choose the smallest cor
31
31
  - Use `executorTurnCallback` when the user needs per-turn observability into generated code, raw runtime result, formatted output, or provider thoughts.
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
 
@@ -45,6 +46,7 @@ Map user intent to agent shape before writing code:
45
46
  - "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
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.
@@ -860,6 +879,35 @@ const supportAgent = agent('query:string -> answer:string', {
860
879
  });
861
880
  ```
862
881
 
882
+ ## Context Event Observability
883
+
884
+ 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.
885
+
886
+ Events:
887
+
888
+ - `budget_check`: character-based prompt pressure before an actor turn, with detailed metrics kept out of the actor prompt.
889
+ - `checkpoint_created` / `checkpoint_cleared`: checkpoint lifecycle events with covered turns and reason.
890
+ - `tombstone_created`: compact resolved-error summary creation.
891
+
892
+ Rules:
893
+
894
+ - `contextPressure` in the actor prompt is intentionally compact (`ok`, `watch`, `critical` plus one short instruction).
895
+ - Budget metrics are character-based for provider neutrality and are exposed through `onContextEvent`, not the actor prompt.
896
+ - Callback errors are swallowed so telemetry cannot break the agent run.
897
+
898
+ ```typescript
899
+ const supportAgent = agent('query:string -> answer:string', {
900
+ contextFields: ['query'],
901
+ runtime,
902
+ contextPolicy: { preset: 'checkpointed', budget: 'balanced' },
903
+ onContextEvent: (event) => {
904
+ if (event.kind === 'budget_check') {
905
+ console.log(event.pressure, event.mutablePromptChars);
906
+ }
907
+ },
908
+ });
909
+ ```
910
+
863
911
  ## Agent Status Callback
864
912
 
865
913
  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.
@@ -1467,6 +1515,7 @@ Use `promptMaxChars` when partial data is worse than no data (e.g. JSON objects)
1467
1515
  isError: boolean;
1468
1516
  thought?: string;
1469
1517
  }) => void | Promise<void>;
1518
+ onContextEvent?: (event: AxAgentContextEvent) => void | Promise<void>;
1470
1519
  inputUpdateCallback?: (currentInputs: Record<string, unknown>) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
1471
1520
  onFunctionCall?: (call: {
1472
1521
  name: string;
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
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.4"
4
+ version: "21.0.6"
5
5
  ---
6
6
 
7
7
  # Ax Signature Reference