@ax-llm/ax 18.0.12 → 19.0.1

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.12",
3
+ "version": "19.0.1",
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
- 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.12"
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, composing multi-agent hierarchies, shared fields, shared agents, or global shared fields/agents.
4
+ version: "19.0.1"
5
5
  ---
6
6
 
7
7
  # AxAgent Guide (@ax-llm/ax)
@@ -84,15 +84,10 @@ const myAgent = agent(
84
84
 
85
85
  // Optional
86
86
  ai: llm, // Bind a specific AI service
87
- functions: [searchTool, calcTool], // Tool functions
88
- agents: [childAgent1, childAgent2], // Child agents
89
- maxSteps: 25, // Max reasoning steps (default: 25)
90
- maxRetries: 3, // Retries on assertion failures
91
- temperature: 0.7, // Sampling temperature
87
+ contextFields: ['...'], // Fields removed from LLM; available in JS runtime
88
+ functions: { local: [searchTool, calcTool] }, // Agent functions (AxAgentFunction)
89
+ agents: { local: [childAgent1, childAgent2] }, // Child agents
92
90
  debug: false, // Debug logging
93
-
94
- // RLM mode (see RLM section below)
95
- contextFields: ['...'], // Fields to load into runtime session
96
91
  // ... other RLM options (see RLM section below)
97
92
  }
98
93
  );
@@ -102,14 +97,6 @@ const myAgent = agent(
102
97
 
103
98
  Required when the agent is used as a child agent. Contains `name` (converted to camelCase for the function name, e.g. `'Physics Researcher'` becomes `physicsResearcher`) and `description` (shown to parent agents when they decide which child to call).
104
99
 
105
- ### `functions`
106
-
107
- An array of tool functions the agent can call. Each function has a name, description, JSON Schema parameters, and an implementation.
108
-
109
- ### `agents`
110
-
111
- An array of child agents. When provided, the agent can delegate subtasks to these children. See [Child Agents](#child-agents).
112
-
113
100
  ## Running Agents
114
101
 
115
102
  ### `forward()`
@@ -293,7 +280,7 @@ const weatherAgent = agent(
293
280
  name: 'weatherAssistant',
294
281
  description: 'An assistant that helps with weather queries',
295
282
  },
296
- functions: [getCurrentWeather]
283
+ functions: { local: [getCurrentWeather] }
297
284
  }
298
285
  );
299
286
 
@@ -330,11 +317,12 @@ const summarizer = agent(
330
317
  name: 'Science Summarizer',
331
318
  description: 'Summarizer can write short summaries of advanced science topics',
332
319
  },
320
+ actorOptions: {
321
+ description: 'You are a science summarizer. You can write short summaries of advanced science topics. Use numbered bullet points to summarize the answer in order of importance.',
322
+ },
333
323
  }
334
324
  );
335
325
 
336
- summarizer.setActorDescription('You are a science summarizer. You can write short summaries of advanced science topics. Use numbered bullet points to summarize the answer in order of importance.');
337
-
338
326
  const scientist = agent(
339
327
  f()
340
328
  .input('question', f.string())
@@ -345,7 +333,7 @@ const scientist = agent(
345
333
  name: 'Scientist',
346
334
  description: 'An agent that can answer advanced science questions',
347
335
  },
348
- agents: [researcher, summarizer],
336
+ agents: { local: [researcher, summarizer] },
349
337
  }
350
338
  );
351
339
 
@@ -354,6 +342,67 @@ const result = await scientist.forward(llm, {
354
342
  });
355
343
  ```
356
344
 
345
+ ## Shared Fields and Agents
346
+
347
+ When composing agent hierarchies, you often need to pass data or utility agents to child agents without requiring the parent's LLM to explicitly route them.
348
+
349
+ ### `fields.shared` — Pass fields to direct children (one level)
350
+
351
+ Fields listed in `fields.shared` are automatically injected into direct child agents at runtime. They bypass the parent's LLM entirely.
352
+
353
+ ```typescript
354
+ const parentAgent = agent('query:string, userId:string, knowledgeBase:string -> answer:string', {
355
+ agents: { local: [childAgent] },
356
+ contextFields: ['knowledgeBase'],
357
+ fields: { shared: ['userId'] }, // userId is injected into child agents automatically
358
+ });
359
+ ```
360
+
361
+ - `userId` is removed from the parent's Actor/Responder prompts
362
+ - Children can opt out via `fields: { excluded: ['userId'] }`
363
+
364
+ ### `fields.globallyShared` — Pass fields to ALL descendants (recursive)
365
+
366
+ Like `fields.shared`, but propagates through the entire agent tree — children, grandchildren, and beyond.
367
+
368
+ ```typescript
369
+ const parent = agent('query:string, sessionId:string -> answer:string', {
370
+ agents: { local: [child] },
371
+ fields: { globallyShared: ['sessionId'] }, // sessionId reaches child AND grandchild
372
+ });
373
+ ```
374
+
375
+ ### `agents.shared` — Add agents to direct children (one level)
376
+
377
+ Utility agents listed in `agents.shared` are added to every direct child agent's available agents list.
378
+
379
+ ```typescript
380
+ const parent = agent('query:string -> answer:string', {
381
+ agents: { local: [worker], shared: [logger] }, // worker can now call agents.logger(...)
382
+ });
383
+ ```
384
+
385
+ ### `agents.globallyShared` — Add agents to ALL descendants (recursive)
386
+
387
+ Like `agents.shared`, but propagates through the entire agent tree.
388
+
389
+ ```typescript
390
+ const parent = agent('query:string -> answer:string', {
391
+ agents: { local: [child], globallyShared: [logger] }, // both child AND grandchild can call agents.logger(...)
392
+ });
393
+ ```
394
+
395
+ ### `fields.excluded`
396
+
397
+ Any child agent can opt out of receiving specific shared fields:
398
+
399
+ ```typescript
400
+ const sentiment = agent('text:string -> sentiment:string', {
401
+ agentIdentity: { name: 'Sentiment', description: 'Analyzes sentiment' },
402
+ fields: { excluded: ['userId'] },
403
+ });
404
+ ```
405
+
357
406
  ## RLM Mode
358
407
 
359
408
  RLM (Recursive Language Model) mode lets agents process arbitrarily long documents without hitting context window limits. Instead of stuffing the entire document into the LLM prompt, RLM loads it into a code interpreter session and gives the LLM tools to analyze it programmatically.
@@ -372,7 +421,7 @@ When you pass a long document to an LLM, you face:
372
421
  - **Actor** — A code generation agent that writes JavaScript to analyze context data. It NEVER generates final answers directly.
373
422
  - **Responder** — An answer synthesis agent that produces the final answer from the Actor's `actorResult` payload. It NEVER generates code.
374
423
  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.
424
+ 4. **Completion** — The Actor signals completion by calling `final(...args)` or asks for more user input with `ask_clarification(...args)`, then the Responder synthesizes the final answer.
376
425
 
377
426
  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.
378
427
 
@@ -529,7 +578,7 @@ The Actor generates JavaScript code in a `javascriptCode` output field. Each tur
529
578
  2. The runtime executes the code and returns the result
530
579
  3. The result is appended to the action log
531
580
  4. The Actor sees the updated action log and decides what to do next
532
- 5. When the Actor calls `submit(...args)` or `ask_clarification(...args)`, the loop ends and the Responder takes over
581
+ 5. When the Actor calls `final(...args)` or `ask_clarification(...args)`, the loop ends and the Responder takes over
533
582
 
534
583
  The Actor's typical workflow:
535
584
 
@@ -538,7 +587,7 @@ The Actor's typical workflow:
538
587
  3. Use code for structural work (filter, map, regex, property access)
539
588
  4. Use llmQuery for semantic work (summarization, interpretation)
540
589
  5. Build up answers in variables across turns
541
- 6. Signal completion by calling `submit(...args)` (or `ask_clarification(...args)` to request user input)
590
+ 6. Signal completion by calling `final(...args)` (or `ask_clarification(...args)` to request user input)
542
591
 
543
592
  ### Actor Fields
544
593
 
@@ -565,7 +614,7 @@ const analyzer = agent(
565
614
 
566
615
  ### Actor Callback
567
616
 
568
- 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.
617
+ Use `actorCallback` to observe each Actor turn. It receives the full Actor result (including `javascriptCode` and any `actorFields`) and fires every turn, including the `final(...)`/`ask_clarification(...)` turn.
569
618
 
570
619
  ```typescript
571
620
  const analyzer = agent(
@@ -637,7 +686,7 @@ Each `llmQuery` call runs a sub-query with a fresh session and the same register
637
686
 
638
687
  ### Actor/Responder Descriptions
639
688
 
640
- 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.
689
+ Use `actorOptions.description` and `responderOptions.description` to append additional instructions to the Actor or Responder system prompts. The base RLM prompts are preserved; your text is appended after them.
641
690
 
642
691
  ```typescript
643
692
  const analyzer = agent(
@@ -652,18 +701,16 @@ const analyzer = agent(
652
701
  description: 'Analyzes context with custom actor and responder instructions',
653
702
  },
654
703
  contextFields: ['context'],
704
+ actorOptions: {
705
+ description: 'Focus on numerical data. Use precise calculations.',
706
+ },
707
+ responderOptions: {
708
+ description: 'Format answers as bullet points. Cite evidence.',
709
+ },
655
710
  }
656
711
  );
657
-
658
- // Add domain-specific instructions to the Actor (code generation agent)
659
- analyzer.setActorDescription('Focus on numerical data. Use precise calculations.');
660
-
661
- // Add domain-specific instructions to the Responder (answer synthesis agent)
662
- analyzer.setResponderDescription('Format answers as bullet points. Cite evidence.');
663
712
  ```
664
713
 
665
- > **Note:** Signature-level descriptions (via `.description()` on the signature) are not supported on `AxAgent`. Use these methods instead to customize each sub-program independently.
666
-
667
714
  ### Few-Shot Demos
668
715
 
669
716
  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.
@@ -681,7 +728,7 @@ analyzer.setDemos([
681
728
  },
682
729
  {
683
730
  actionLog: 'Step 1 | console.log(context.slice(0, 200))\n→ Chapter 1: ...',
684
- javascriptCode: 'submit("analysis complete")',
731
+ javascriptCode: 'final("analysis complete")',
685
732
  },
686
733
  ],
687
734
  },
@@ -706,10 +753,10 @@ Demo values are validated against the target program's signature. Invalid values
706
753
  |-----|-------------|
707
754
  | `await llmQuery(query, context)` | Ask a sub-LM a question with a context value. Returns a string. Oversized context is truncated to `maxRuntimeChars` |
708
755
  | `await llmQuery([{ query, context }, ...])` | Run multiple sub-LM queries in parallel. Returns string[]. Failed items return `[ERROR] ...` |
709
- | `submit(...args)` | Stop Actor execution and pass payload args to Responder. Requires at least one argument |
756
+ | `final(...args)` | Stop Actor execution and pass payload args to Responder. Requires at least one argument |
710
757
  | `ask_clarification(...args)` | Stop Actor execution and pass clarification payload args to Responder. Requires at least one argument |
711
758
  | `await agents.<name>({...})` | Call a child agent by name. Parameters match the agent's JSON schema. Returns a string |
712
- | `await <toolName>({...})` | Call a tool function by name. Parameters match the tool's JSON schema |
759
+ | `await <namespace>.<name>({...})` | Call an agent function. Registered under `namespace.name` (default namespace: `utils`) |
713
760
  | `print(...args)` | Available in `AxJSRuntime` when `outputMode: 'stdout'`; captured output appears in the function result |
714
761
  | Context variables | All fields listed in `contextFields` are available by name |
715
762
 
@@ -803,9 +850,9 @@ class MyBrowserInterpreter implements AxCodeRuntime {
803
850
  The `globals` object passed to `createSession` includes:
804
851
  - All context field values (by field name)
805
852
  - `llmQuery` function (supports both single and batched queries)
806
- - `submit(...args)` and `ask_clarification(...args)` completion functions
853
+ - `final(...args)` and `ask_clarification(...args)` completion functions
807
854
  - `agents` namespace object with child agent functions (e.g., `agents.summarize(...)`)
808
- - Tool functions as flat globals
855
+ - `<namespace>` objects containing agent functions (e.g., `globals.utils.search(...)`)
809
856
  - `print` function when supported by the runtime (for `AxJSRuntime`, set `outputMode: 'stdout'`)
810
857
 
811
858
  If provided, `getUsageInstructions()` is appended to the RLM system prompt as runtime-specific guidance. Use it for semantics that differ by runtime (for example state persistence or async execution behavior).
@@ -887,11 +934,22 @@ interface AxCodeSession {
887
934
  interface AxAgentConfig<IN, OUT> extends AxAgentOptions {
888
935
  ai?: AxAIService;
889
936
  agentIdentity?: { name: string; description: string };
890
- agents?: AxAgentic<IN, OUT>[];
891
- functions?: AxInputFunctionType;
892
937
  }
893
938
  ```
894
939
 
940
+ ### `AxAgentFunction`
941
+
942
+ ```typescript
943
+ type AxAgentFunction = {
944
+ name: string;
945
+ description: string;
946
+ parameters: AxFunctionJSONSchema; // required
947
+ returns?: AxFunctionJSONSchema;
948
+ namespace?: string; // default: 'utils'
949
+ func: AxFunctionHandler;
950
+ };
951
+ ```
952
+
895
953
  ### `AxAgentOptions`
896
954
 
897
955
  Extends `AxProgramForwardOptions` (without `functions`) with:
@@ -900,12 +958,33 @@ Extends `AxProgramForwardOptions` (without `functions`) with:
900
958
  {
901
959
  debug?: boolean;
902
960
  contextFields: string[];
961
+
962
+ agents?: {
963
+ local?: AxAnyAgentic[]; // Agents callable under the agents.* namespace
964
+ shared?: AxAnyAgentic[]; // Added to all direct child agents (one level)
965
+ globallyShared?: AxAnyAgentic[]; // Added to ALL descendants recursively
966
+ excluded?: string[]; // Agent names this agent should NOT receive from parents
967
+ };
968
+
969
+ fields?: {
970
+ shared?: string[]; // Fields passed to direct child agents (one level)
971
+ globallyShared?: string[]; // Fields passed to ALL descendants recursively
972
+ excluded?: string[]; // Fields this agent should NOT receive from parents
973
+ };
974
+
975
+ functions?: {
976
+ local?: AxAgentFunction[]; // Registered as namespace.name globals in the JS runtime
977
+ shared?: AxAgentFunction[]; // Shared with direct child agents (one level)
978
+ globallyShared?: AxAgentFunction[]; // Shared with ALL descendants recursively
979
+ excluded?: string[]; // Function names this agent should NOT receive from parents
980
+ };
981
+
903
982
  runtime?: AxCodeRuntime;
904
983
  maxLlmCalls?: number;
905
984
  maxRuntimeChars?: number;
906
985
  maxBatchedLlmQueryConcurrency?: number;
907
986
  maxTurns?: number;
908
- trajectoryPruning?: boolean; // @deprecated Use contextManagement.errorPruning
987
+ trajectoryPruning?: boolean; // @deprecated Use contextManagement.errorPruning
909
988
  contextManagement?: AxContextManagementConfig;
910
989
  actorFields?: string[];
911
990
  actorCallback?: (result: Record<string, unknown>) => void | Promise<void>;
@@ -913,27 +992,11 @@ Extends `AxProgramForwardOptions` (without `functions`) with:
913
992
  recursionOptions?: Partial<Omit<AxProgramForwardOptions, 'functions'>> & {
914
993
  maxDepth?: number; // Maximum recursion depth for llmQuery sub-agent calls (default: 2)
915
994
  };
916
- actorOptions?: Partial<AxProgramForwardOptions>; // Default forward options for Actor
917
- responderOptions?: Partial<AxProgramForwardOptions>; // Default forward options for Responder
995
+ actorOptions?: Partial<AxProgramForwardOptions & { description?: string }>; // Default forward options for Actor
996
+ responderOptions?: Partial<AxProgramForwardOptions & { description?: string }>; // Default forward options for Responder
918
997
  }
919
998
  ```
920
999
 
921
- ### `setActorDescription()`
922
-
923
- ```typescript
924
- public setActorDescription(additionalText: string): void
925
- ```
926
-
927
- Appends additional text to the Actor's RLM system prompt. The base prompt is preserved; the additional text is appended after it.
928
-
929
- ### `setResponderDescription()`
930
-
931
- ```typescript
932
- public setResponderDescription(additionalText: string): void
933
- ```
934
-
935
- Appends additional text to the Responder's RLM system prompt. The base prompt is preserved; the additional text is appended after it.
936
-
937
1000
  ### `stop()`
938
1001
 
939
1002
  ```typescript
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.12"
4
+ version: "19.0.1"
5
5
  ---
6
6
 
7
7
  # Ax Library (@ax-llm/ax) Usage Guide