@ax-llm/ax 18.0.7 → 18.0.9

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": "18.0.7",
3
+ "version": "18.0.9",
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 with building AxAgent-based agents using @ax-llm/ax. Use when the user asks about agent(), AxAgent, child agents, tool functions, RLM mode, stopping agents, or composing multi-agent hierarchies.
4
- version: "18.0.7"
4
+ version: "18.0.9"
5
5
  ---
6
6
 
7
7
  # AxAgent Guide (@ax-llm/ax)
@@ -399,7 +399,13 @@ const analyzer = agent(
399
399
  maxRuntimeChars: 2_000, // Cap for llmQuery context + code output (default: 5000)
400
400
  maxBatchedLlmQueryConcurrency: 6, // Max parallel batched llmQuery calls (default: 8)
401
401
  maxTurns: 10, // Max Actor turns before forcing Responder (default: 10)
402
- compressLog: true, // Store actionDescription in actionLog instead of full code
402
+ contextManagement: { // Semantic context management (replaces trajectoryPruning)
403
+ errorPruning: true, // Prune error entries after successful turns
404
+ hindsightEvaluation: true, // Heuristic importance scoring on entries
405
+ tombstoning: true, // Replace resolved errors with compact summaries
406
+ stateInspection: { contextThreshold: 2000 }, // Enable inspect_runtime() tool
407
+ pruneRank: 2, // Entries ranked below this are purged (0-5, default: 2)
408
+ },
403
409
  actorFields: ['reasoning'], // Output fields produced by Actor instead of Responder
404
410
  actorCallback: async (result) => { // Called after each Actor turn
405
411
  console.log('Actor turn:', result);
@@ -441,6 +447,31 @@ Available permissions:
441
447
 
442
448
  > **Warning**: Granting `WORKERS` allows code to spawn sub-workers that get fresh, unlocked globals. A child worker has full access to `fetch`, `indexedDB`, etc. regardless of the parent's permissions. Only grant `WORKERS` when you trust the executed code.
443
449
 
450
+ ### Consecutive Execution Error Cutoff
451
+
452
+ `AxJSRuntime` can enforce a cutoff for consecutive execution failures:
453
+
454
+ ```typescript
455
+ import { AxJSRuntime } from '@ax-llm/ax';
456
+
457
+ const runtime = new AxJSRuntime({
458
+ consecutiveErrorCutoff: 3,
459
+ });
460
+ ```
461
+
462
+ Behavior:
463
+
464
+ - The runtime tracks consecutive execution failures.
465
+ - The counter resets on successful execution.
466
+ - When failures hit the configured cutoff, the runtime throws `AxRuntimeExecutionError` and exits the session.
467
+ - Preflight guardrail errors are not counted (for example blocked `"use strict"` and reserved-name reassignment checks).
468
+
469
+ You can manually reset the runtime-level counter:
470
+
471
+ ```typescript
472
+ runtime.resetConsecutiveErrorCounter();
473
+ ```
474
+
444
475
  ### Structured Context Fields
445
476
 
446
477
  Context fields aren't limited to plain strings. You can pass structured data — objects and arrays with typed sub-fields:
@@ -721,18 +752,24 @@ but `globalThis.state = ...` (or mutating a shared `state` object) is the recomm
721
752
  Errors thrown by code running inside `session.execute(code)` cross the worker boundary and can be caught on the host. Always `await` `session.execute()` inside a try/catch:
722
753
 
723
754
  ```typescript
755
+ import { AxRuntimeExecutionError } from '@ax-llm/ax';
756
+
724
757
  try {
725
758
  const result = await session.execute(code);
726
759
  // use result
727
760
  } catch (e) {
728
- // e is an Error with name and message preserved from the worker
729
- if (e instanceof Error && e.name === 'WaitForUserActionError') {
761
+ if (e instanceof AxRuntimeExecutionError) {
762
+ // Consecutive execution failures reached the cutoff; session was exited.
763
+ } else if (e instanceof Error && e.name === 'WaitForUserActionError') {
730
764
  // handle domain-specific error
731
765
  }
732
- console.error(e.message);
766
+ console.error(e instanceof Error ? e.message : String(e));
733
767
  }
734
768
  ```
735
769
 
770
+ - **`AxRuntimeExecutionError`** is thrown when the runtime reaches the configured consecutive execution failure cutoff.
771
+ - The cutoff counter **resets on successful execution**.
772
+ - **Preflight guardrail errors are not counted** toward the cutoff.
736
773
  - **`e.name`** and **`e.message`** are preserved, so you can branch on `e.name === 'WaitForUserActionError'` (or other custom error names) and use `e.message` for user-facing context.
737
774
  - **`e.cause`** is preserved when structured-cloneable, including recursive cause chains (with a depth limit).
738
775
  - **`e.data`** (optional) is preserved when the thrown error has a `data` property set to a structured-cloneable value (object, array, string, number, etc.). Use it for custom payloads (e.g. `(e as Error & { data?: unknown }).data`). Non-cloneable values are omitted.
@@ -779,6 +816,27 @@ RLM mode does not support true streaming. When using `streamingForward`, RLM run
779
816
 
780
817
  ## API Reference
781
818
 
819
+ ### `AxJSRuntime`
820
+
821
+ ```typescript
822
+ new AxJSRuntime({
823
+ timeout?: number;
824
+ permissions?: readonly AxJSRuntimePermission[];
825
+ outputMode?: 'return' | 'stdout';
826
+ captureConsole?: boolean;
827
+ allowUnsafeNodeHostAccess?: boolean;
828
+ nodeWorkerPoolSize?: number;
829
+ debugNodeWorkerPool?: boolean;
830
+ consecutiveErrorCutoff?: number; // Cutoff for consecutive execution failures
831
+ });
832
+
833
+ runtime.resetConsecutiveErrorCounter(): void; // Resets runtime-level consecutive failure counter
834
+ ```
835
+
836
+ ### `AxRuntimeExecutionError`
837
+
838
+ Thrown by `AxJSRuntime` when consecutive execution failures reach `consecutiveErrorCutoff`. When this happens, the active runtime session is exited. Preflight guardrail errors are not counted toward this cutoff.
839
+
782
840
  ### `AxRLMConfig`
783
841
 
784
842
  ```typescript
@@ -789,11 +847,20 @@ interface AxRLMConfig {
789
847
  maxRuntimeChars?: number; // Cap for llmQuery context + code output (default: 5000)
790
848
  maxBatchedLlmQueryConcurrency?: number; // Max parallel batched llmQuery calls (default: 8)
791
849
  maxTurns?: number; // Max Actor turns before forcing Responder (default: 10)
792
- compressLog?: boolean; // Use actionDescription entries instead of full code in actionLog
850
+ trajectoryPruning?: boolean; // @deprecated Use contextManagement.errorPruning instead
851
+ contextManagement?: AxContextManagementConfig; // Semantic context management
793
852
  actorFields?: string[]; // Output fields produced by Actor instead of Responder
794
853
  actorCallback?: (result: Record<string, unknown>) => void | Promise<void>; // Called after each Actor turn
795
854
  mode?: 'simple' | 'advanced'; // Sub-query mode: 'simple' = AxGen, 'advanced' = AxAgent (default: 'simple')
796
855
  }
856
+
857
+ interface AxContextManagementConfig {
858
+ errorPruning?: boolean; // Prune error entries after successful turns
859
+ tombstoning?: boolean | Omit<AxProgramForwardOptions<string>, 'functions'>; // Replace resolved errors with compact summaries
860
+ hindsightEvaluation?: boolean; // Heuristic importance scoring on entries
861
+ stateInspection?: { contextThreshold?: number }; // Enable inspect_runtime() tool
862
+ pruneRank?: number; // Entries ranked below this are purged (0-5, default: 2)
863
+ }
797
864
  ```
798
865
 
799
866
  ### `AxCodeRuntime`
@@ -838,7 +905,8 @@ Extends `AxProgramForwardOptions` (without `functions`) with:
838
905
  maxRuntimeChars?: number;
839
906
  maxBatchedLlmQueryConcurrency?: number;
840
907
  maxTurns?: number;
841
- compressLog?: boolean;
908
+ trajectoryPruning?: boolean; // @deprecated Use contextManagement.errorPruning
909
+ contextManagement?: AxContextManagementConfig;
842
910
  actorFields?: string[];
843
911
  actorCallback?: (result: Record<string, unknown>) => void | Promise<void>;
844
912
  mode?: 'simple' | 'advanced';
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: "18.0.7"
4
+ version: "18.0.9"
5
5
  ---
6
6
 
7
7
  # Ax Library (@ax-llm/ax) Usage Guide