@ax-llm/ax 18.0.2 → 18.0.4

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.2",
3
+ "version": "18.0.4",
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.2"
4
+ version: "18.0.4"
5
5
  ---
6
6
 
7
7
  # AxAgent Guide (@ax-llm/ax)
@@ -92,7 +92,8 @@ const myAgent = agent(
92
92
  debug: false, // Debug logging
93
93
 
94
94
  // RLM mode (see RLM section below)
95
- rlm: { ... },
95
+ contextFields: ['...'], // Fields to load into runtime session
96
+ // ... other RLM options (see RLM section below)
96
97
  }
97
98
  );
98
99
  ```
@@ -369,9 +370,9 @@ When you pass a long document to an LLM, you face:
369
370
  1. **Context extraction** — Fields listed in `contextFields` are removed from the LLM prompt and loaded into a runtime session as variables.
370
371
  2. **Actor/Responder split** — The agent uses two internal programs:
371
372
  - **Actor** — A code generation agent that writes JavaScript to analyze context data. It NEVER generates final answers directly.
372
- - **Responder** — An answer synthesis agent that produces the final answer from the Actor's action log. It NEVER generates code.
373
- 3. **Sub-LM queries** — Inside code, `llmQuery(...)` delegates semantic work to a sub-model.
374
- 4. **Completion** — The Actor signals done by calling `done()` (standalone or inline with other code), then the Responder synthesizes the final answer.
373
+ - **Responder** — An answer synthesis agent that produces the final answer from the Actor's `actorResult` payload. It NEVER generates code.
374
+ 3. **Recursive queries** — Inside code, `llmQuery(...)` delegates semantic work to a sub-query (plain AxGen in simple mode, full AxAgent in advanced mode).
375
+ 4. **Completion** — The Actor signals completion by calling `submit(...args)` or asks for more user input with `ask_clarification(...args)`, then the Responder synthesizes the final answer.
375
376
 
376
377
  The Actor writes JavaScript code to inspect, filter, and iterate over the document. It uses `llmQuery` for semantic analysis and can chunk data in code before querying.
377
378
 
@@ -392,18 +393,21 @@ const analyzer = agent(
392
393
  name: 'documentAnalyzer',
393
394
  description: 'Analyzes long documents using code interpreter and sub-LM queries',
394
395
  },
395
- rlm: {
396
- contextFields: ['context'], // Fields to load into runtime session
397
- runtime: new AxJSRuntime(), // Code runtime (default: AxJSRuntime)
398
- maxLlmCalls: 30, // Cap on sub-LM calls (default: 50)
399
- maxRuntimeChars: 2_000, // Cap for llmQuery context + code output (default: 5000)
400
- maxBatchedLlmQueryConcurrency: 6, // Max parallel batched llmQuery calls (default: 8)
401
- subModel: 'gpt-4o-mini', // Model for llmQuery (default: same as parent)
402
- maxTurns: 10, // Max Actor turns before forcing Responder (default: 10)
403
- actorFields: ['reasoning'], // Output fields produced by Actor instead of Responder
404
- actorCallback: async (result) => { // Called after each Actor turn
405
- console.log('Actor turn:', result);
406
- },
396
+ contextFields: ['context'], // Fields to load into runtime session
397
+ runtime: new AxJSRuntime(), // Code runtime (default: AxJSRuntime)
398
+ maxLlmCalls: 30, // Cap on sub-LM calls (default: 50)
399
+ maxRuntimeChars: 2_000, // Cap for llmQuery context + code output (default: 5000)
400
+ maxBatchedLlmQueryConcurrency: 6, // Max parallel batched llmQuery calls (default: 8)
401
+ maxTurns: 10, // Max Actor turns before forcing Responder (default: 10)
402
+ compressLog: true, // Store actionDescription in actionLog instead of full code
403
+ actorFields: ['reasoning'], // Output fields produced by Actor instead of Responder
404
+ actorCallback: async (result) => { // Called after each Actor turn
405
+ console.log('Actor turn:', result);
406
+ },
407
+ mode: 'simple', // Sub-query mode: 'simple' = AxGen, 'advanced' = AxAgent (default: 'simple')
408
+ recursionOptions: {
409
+ model: 'gpt-4o-mini', // Forward options for recursive llmQuery agent calls
410
+ maxDepth: 2, // Maximum recursion depth
407
411
  },
408
412
  }
409
413
  );
@@ -461,10 +465,8 @@ const analyzer = agent(sig, {
461
465
  name: 'structuredAnalyzer',
462
466
  description: 'Analyzes structured document collections using RLM',
463
467
  },
464
- rlm: {
465
- contextFields: ['documents'],
466
- runtime: new AxJSRuntime(),
467
- },
468
+ contextFields: ['documents'],
469
+ runtime: new AxJSRuntime(),
468
470
  });
469
471
  ```
470
472
 
@@ -496,7 +498,7 @@ The Actor generates JavaScript code in a `javascriptCode` output field. Each tur
496
498
  2. The runtime executes the code and returns the result
497
499
  3. The result is appended to the action log
498
500
  4. The Actor sees the updated action log and decides what to do next
499
- 5. When the Actor calls `done()` (standalone or inline with other code), the loop ends and the Responder takes over
501
+ 5. When the Actor calls `submit(...args)` or `ask_clarification(...args)`, the loop ends and the Responder takes over
500
502
 
501
503
  The Actor's typical workflow:
502
504
 
@@ -505,7 +507,7 @@ The Actor's typical workflow:
505
507
  3. Use code for structural work (filter, map, regex, property access)
506
508
  4. Use llmQuery for semantic work (summarization, interpretation)
507
509
  5. Build up answers in variables across turns
508
- 6. Signal done by calling `done()` can be standalone or combined with final code
510
+ 6. Signal completion by calling `submit(...args)` (or `ask_clarification(...args)` to request user input)
509
511
 
510
512
  ### Actor Fields
511
513
 
@@ -524,17 +526,15 @@ const analyzer = agent(
524
526
  name: 'reasoningAnalyzer',
525
527
  description: 'Analyzes context with explicit reasoning steps',
526
528
  },
527
- rlm: {
528
- contextFields: ['context'],
529
- actorFields: ['reasoning'], // Actor produces 'reasoning', Responder produces 'answer'
530
- },
529
+ contextFields: ['context'],
530
+ actorFields: ['reasoning'], // Actor produces 'reasoning', Responder produces 'answer'
531
531
  }
532
532
  );
533
533
  ```
534
534
 
535
535
  ### Actor Callback
536
536
 
537
- Use `actorCallback` to observe each Actor turn. It receives the full Actor result (including `javascriptCode` and any `actorFields`) and fires every turn, including the done() turn.
537
+ Use `actorCallback` to observe each Actor turn. It receives the full Actor result (including `javascriptCode` and any `actorFields`) and fires every turn, including the `submit(...)`/`ask_clarification(...)` turn.
538
538
 
539
539
  ```typescript
540
540
  const analyzer = agent(
@@ -548,11 +548,9 @@ const analyzer = agent(
548
548
  name: 'callbackAnalyzer',
549
549
  description: 'Analyzes context with observable actor turns',
550
550
  },
551
- rlm: {
552
- contextFields: ['context'],
553
- actorCallback: async (result) => {
554
- console.log('Actor code:', result.javascriptCode);
555
- },
551
+ contextFields: ['context'],
552
+ actorCallback: async (result) => {
553
+ console.log('Actor code:', result.javascriptCode);
556
554
  },
557
555
  }
558
556
  );
@@ -574,7 +572,7 @@ const analyzer = agent(
574
572
  name: 'dualModelAnalyzer',
575
573
  description: 'Analyzes context using different models for actor and responder',
576
574
  },
577
- rlm: { contextFields: ['context'] },
575
+ contextFields: ['context'],
578
576
  actorOptions: {
579
577
  model: 'fast-model',
580
578
  thinkingTokenBudget: 1024,
@@ -589,6 +587,23 @@ const analyzer = agent(
589
587
 
590
588
  Priority order (low to high): constructor base options < `actorOptions`/`responderOptions` < forward-time options.
591
589
 
590
+ ### Recursive llmQuery Options
591
+
592
+ Use `recursionOptions` to set default forward options for recursive `llmQuery` sub-agent calls.
593
+
594
+ ```typescript
595
+ const analyzer = agent('context:string, query:string -> answer:string', {
596
+ contextFields: ['context'],
597
+ recursionOptions: {
598
+ model: 'fast-model',
599
+ maxDepth: 2,
600
+ timeout: 60_000,
601
+ },
602
+ });
603
+ ```
604
+
605
+ Each `llmQuery` call runs a sub-query with a fresh session and the same registered tool/agent globals. The child receives only the `context` argument passed to `llmQuery(query, context)` — parent `contextFields` values are not forwarded. In simple mode (default), the child is a plain AxGen (direct LLM call). In advanced mode, the child is a full AxAgent with Actor/Responder and code runtime.
606
+
592
607
  ### Actor/Responder Descriptions
593
608
 
594
609
  Use `setActorDescription()` and `setResponderDescription()` to append additional instructions to the Actor or Responder system prompts. The base RLM prompts are preserved; your text is appended after them.
@@ -605,7 +620,7 @@ const analyzer = agent(
605
620
  name: 'customAnalyzer',
606
621
  description: 'Analyzes context with custom actor and responder instructions',
607
622
  },
608
- rlm: { contextFields: ['context'] },
623
+ contextFields: ['context'],
609
624
  }
610
625
  );
611
626
 
@@ -622,7 +637,7 @@ analyzer.setResponderDescription('Format answers as bullet points. Cite evidence
622
637
 
623
638
  Use `setDemos()` to provide few-shot examples that guide the Actor and Responder. Demos are keyed by program ID — use `namedPrograms()` to discover available IDs.
624
639
 
625
- Each demo trace must include at least one input field AND one output field. The Actor's input fields are `contextMetadata`, `actionLog`, and any non-context inputs from the original signature. The Responder's input fields are the same.
640
+ Each demo trace must include at least one input field AND one output field. The Actor's input fields are `contextMetadata`, `actionLog`, and any non-context inputs from the original signature. The Responder's input fields are `contextMetadata`, `actorResult`, and any non-context inputs from the original signature.
626
641
 
627
642
  ```typescript
628
643
  analyzer.setDemos([
@@ -635,7 +650,7 @@ analyzer.setDemos([
635
650
  },
636
651
  {
637
652
  actionLog: 'Step 1 | console.log(context.slice(0, 200))\n→ Chapter 1: ...',
638
- javascriptCode: 'done()',
653
+ javascriptCode: 'submit("analysis complete")',
639
654
  },
640
655
  ],
641
656
  },
@@ -658,8 +673,10 @@ Demo values are validated against the target program's signature. Invalid values
658
673
 
659
674
  | API | Description |
660
675
  |-----|-------------|
661
- | `await llmQuery(query, context?)` | Ask a sub-LM a question, optionally with a context string. Returns a string. Oversized context is truncated to `maxRuntimeChars` |
662
- | `await llmQuery([{ query, context? }, ...])` | Run multiple sub-LM queries in parallel. Returns string[]. Failed items return `[ERROR] ...` |
676
+ | `await llmQuery(query, context)` | Ask a sub-LM a question with a context value. Returns a string. Oversized context is truncated to `maxRuntimeChars` |
677
+ | `await llmQuery([{ query, context }, ...])` | Run multiple sub-LM queries in parallel. Returns string[]. Failed items return `[ERROR] ...` |
678
+ | `submit(...args)` | Stop Actor execution and pass payload args to Responder. Requires at least one argument |
679
+ | `ask_clarification(...args)` | Stop Actor execution and pass clarification payload args to Responder. Requires at least one argument |
663
680
  | `await agents.<name>({...})` | Call a child agent by name. Parameters match the agent's JSON schema. Returns a string |
664
681
  | `await <toolName>({...})` | Call a tool function by name. Parameters match the tool's JSON schema |
665
682
  | `print(...args)` | Available in `AxJSRuntime` when `outputMode: 'stdout'`; captured output appears in the function result |
@@ -749,6 +766,7 @@ class MyBrowserInterpreter implements AxCodeRuntime {
749
766
  The `globals` object passed to `createSession` includes:
750
767
  - All context field values (by field name)
751
768
  - `llmQuery` function (supports both single and batched queries)
769
+ - `submit(...args)` and `ask_clarification(...args)` completion functions
752
770
  - `agents` namespace object with child agent functions (e.g., `agents.summarize(...)`)
753
771
  - Tool functions as flat globals
754
772
  - `print` function when supported by the runtime (for `AxJSRuntime`, set `outputMode: 'stdout'`)
@@ -770,10 +788,11 @@ interface AxRLMConfig {
770
788
  maxLlmCalls?: number; // Cap on sub-LM calls (default: 50)
771
789
  maxRuntimeChars?: number; // Cap for llmQuery context + code output (default: 5000)
772
790
  maxBatchedLlmQueryConcurrency?: number; // Max parallel batched llmQuery calls (default: 8)
773
- subModel?: string; // Model for llmQuery sub-calls
774
791
  maxTurns?: number; // Max Actor turns before forcing Responder (default: 10)
792
+ compressLog?: boolean; // Use actionDescription entries instead of full code in actionLog
775
793
  actorFields?: string[]; // Output fields produced by Actor instead of Responder
776
794
  actorCallback?: (result: Record<string, unknown>) => void | Promise<void>; // Called after each Actor turn
795
+ mode?: 'simple' | 'advanced'; // Sub-query mode: 'simple' = AxGen, 'advanced' = AxAgent (default: 'simple')
777
796
  }
778
797
  ```
779
798
 
@@ -813,7 +832,19 @@ Extends `AxProgramForwardOptions` (without `functions`) with:
813
832
  ```typescript
814
833
  {
815
834
  debug?: boolean;
816
- rlm: AxRLMConfig;
835
+ contextFields: string[];
836
+ runtime?: AxCodeRuntime;
837
+ maxLlmCalls?: number;
838
+ maxRuntimeChars?: number;
839
+ maxBatchedLlmQueryConcurrency?: number;
840
+ maxTurns?: number;
841
+ compressLog?: boolean;
842
+ actorFields?: string[];
843
+ actorCallback?: (result: Record<string, unknown>) => void | Promise<void>;
844
+ mode?: 'simple' | 'advanced';
845
+ recursionOptions?: Partial<Omit<AxProgramForwardOptions, 'functions'>> & {
846
+ maxDepth?: number; // Maximum recursion depth for llmQuery sub-agent calls (default: 2)
847
+ };
817
848
  actorOptions?: Partial<AxProgramForwardOptions>; // Default forward options for Actor
818
849
  responderOptions?: Partial<AxProgramForwardOptions>; // Default forward options for Responder
819
850
  }
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.2"
4
+ version: "18.0.4"
5
5
  ---
6
6
 
7
7
  # Ax Library (@ax-llm/ax) Usage Guide