@ax-llm/ax 18.0.13 → 19.0.2

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.13",
3
+ "version": "19.0.2",
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, composing multi-agent hierarchies, shared fields, shared agents, or global shared fields/agents.
4
- version: "18.0.13"
4
+ version: "19.0.2"
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
 
@@ -358,62 +346,60 @@ const result = await scientist.forward(llm, {
358
346
 
359
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.
360
348
 
361
- ### `sharedFields` — Pass fields to direct children (one level)
349
+ ### `fields.shared` — Pass fields to direct children (one level)
362
350
 
363
- Fields listed in `sharedFields` are automatically injected into direct child agents at runtime. They bypass the parent's LLM entirely.
351
+ Fields listed in `fields.shared` are automatically injected into direct child agents at runtime. They bypass the parent's LLM entirely.
364
352
 
365
353
  ```typescript
366
354
  const parentAgent = agent('query:string, userId:string, knowledgeBase:string -> answer:string', {
367
- agents: [childAgent],
355
+ agents: { local: [childAgent] },
368
356
  contextFields: ['knowledgeBase'],
369
- sharedFields: ['userId'], // userId is injected into child agents automatically
357
+ fields: { shared: ['userId'] }, // userId is injected into child agents automatically
370
358
  });
371
359
  ```
372
360
 
373
361
  - `userId` is removed from the parent's Actor/Responder prompts
374
- - Children can opt out via `excludeSharedFields: ['userId']`
362
+ - Children can opt out via `fields: { excluded: ['userId'] }`
375
363
 
376
- ### `globalSharedFields` — Pass fields to ALL descendants (recursive)
364
+ ### `fields.globallyShared` — Pass fields to ALL descendants (recursive)
377
365
 
378
- Like `sharedFields`, but propagates through the entire agent tree — children, grandchildren, and beyond.
366
+ Like `fields.shared`, but propagates through the entire agent tree — children, grandchildren, and beyond.
379
367
 
380
368
  ```typescript
381
369
  const parent = agent('query:string, sessionId:string -> answer:string', {
382
- agents: [child],
383
- globalSharedFields: ['sessionId'], // sessionId reaches child AND grandchild
370
+ agents: { local: [child] },
371
+ fields: { globallyShared: ['sessionId'] }, // sessionId reaches child AND grandchild
384
372
  });
385
373
  ```
386
374
 
387
- ### `sharedAgents` — Add agents to direct children (one level)
375
+ ### `agents.shared` — Add agents to direct children (one level)
388
376
 
389
- Utility agents listed in `sharedAgents` are added to every direct child agent's available agents list.
377
+ Utility agents listed in `agents.shared` are added to every direct child agent's available agents list.
390
378
 
391
379
  ```typescript
392
380
  const parent = agent('query:string -> answer:string', {
393
- agents: [worker],
394
- sharedAgents: [logger], // worker can now call agents.logger(...)
381
+ agents: { local: [worker], shared: [logger] }, // worker can now call agents.logger(...)
395
382
  });
396
383
  ```
397
384
 
398
- ### `globalSharedAgents` — Add agents to ALL descendants (recursive)
385
+ ### `agents.globallyShared` — Add agents to ALL descendants (recursive)
399
386
 
400
- Like `sharedAgents`, but propagates through the entire agent tree.
387
+ Like `agents.shared`, but propagates through the entire agent tree.
401
388
 
402
389
  ```typescript
403
390
  const parent = agent('query:string -> answer:string', {
404
- agents: [child],
405
- globalSharedAgents: [logger], // both child AND grandchild can call agents.logger(...)
391
+ agents: { local: [child], globallyShared: [logger] }, // both child AND grandchild can call agents.logger(...)
406
392
  });
407
393
  ```
408
394
 
409
- ### `excludeSharedFields`
395
+ ### `fields.excluded`
410
396
 
411
397
  Any child agent can opt out of receiving specific shared fields:
412
398
 
413
399
  ```typescript
414
400
  const sentiment = agent('text:string -> sentiment:string', {
415
401
  agentIdentity: { name: 'Sentiment', description: 'Analyzes sentiment' },
416
- excludeSharedFields: ['userId'],
402
+ fields: { excluded: ['userId'] },
417
403
  });
418
404
  ```
419
405
 
@@ -435,7 +421,7 @@ When you pass a long document to an LLM, you face:
435
421
  - **Actor** — A code generation agent that writes JavaScript to analyze context data. It NEVER generates final answers directly.
436
422
  - **Responder** — An answer synthesis agent that produces the final answer from the Actor's `actorResult` payload. It NEVER generates code.
437
423
  3. **Recursive queries** — Inside code, `llmQuery(...)` delegates semantic work to a sub-query (plain AxGen in simple mode, full AxAgent in advanced mode).
438
- 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.
439
425
 
440
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.
441
427
 
@@ -592,7 +578,7 @@ The Actor generates JavaScript code in a `javascriptCode` output field. Each tur
592
578
  2. The runtime executes the code and returns the result
593
579
  3. The result is appended to the action log
594
580
  4. The Actor sees the updated action log and decides what to do next
595
- 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
596
582
 
597
583
  The Actor's typical workflow:
598
584
 
@@ -601,7 +587,7 @@ The Actor's typical workflow:
601
587
  3. Use code for structural work (filter, map, regex, property access)
602
588
  4. Use llmQuery for semantic work (summarization, interpretation)
603
589
  5. Build up answers in variables across turns
604
- 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)
605
591
 
606
592
  ### Actor Fields
607
593
 
@@ -628,7 +614,7 @@ const analyzer = agent(
628
614
 
629
615
  ### Actor Callback
630
616
 
631
- 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.
632
618
 
633
619
  ```typescript
634
620
  const analyzer = agent(
@@ -700,7 +686,7 @@ Each `llmQuery` call runs a sub-query with a fresh session and the same register
700
686
 
701
687
  ### Actor/Responder Descriptions
702
688
 
703
- 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.
704
690
 
705
691
  ```typescript
706
692
  const analyzer = agent(
@@ -715,18 +701,16 @@ const analyzer = agent(
715
701
  description: 'Analyzes context with custom actor and responder instructions',
716
702
  },
717
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
+ },
718
710
  }
719
711
  );
720
-
721
- // Add domain-specific instructions to the Actor (code generation agent)
722
- analyzer.setActorDescription('Focus on numerical data. Use precise calculations.');
723
-
724
- // Add domain-specific instructions to the Responder (answer synthesis agent)
725
- analyzer.setResponderDescription('Format answers as bullet points. Cite evidence.');
726
712
  ```
727
713
 
728
- > **Note:** Signature-level descriptions (via `.description()` on the signature) are not supported on `AxAgent`. Use these methods instead to customize each sub-program independently.
729
-
730
714
  ### Few-Shot Demos
731
715
 
732
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.
@@ -744,7 +728,7 @@ analyzer.setDemos([
744
728
  },
745
729
  {
746
730
  actionLog: 'Step 1 | console.log(context.slice(0, 200))\n→ Chapter 1: ...',
747
- javascriptCode: 'submit("analysis complete")',
731
+ javascriptCode: 'final("analysis complete")',
748
732
  },
749
733
  ],
750
734
  },
@@ -769,10 +753,10 @@ Demo values are validated against the target program's signature. Invalid values
769
753
  |-----|-------------|
770
754
  | `await llmQuery(query, context)` | Ask a sub-LM a question with a context value. Returns a string. Oversized context is truncated to `maxRuntimeChars` |
771
755
  | `await llmQuery([{ query, context }, ...])` | Run multiple sub-LM queries in parallel. Returns string[]. Failed items return `[ERROR] ...` |
772
- | `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 |
773
757
  | `ask_clarification(...args)` | Stop Actor execution and pass clarification payload args to Responder. Requires at least one argument |
774
758
  | `await agents.<name>({...})` | Call a child agent by name. Parameters match the agent's JSON schema. Returns a string |
775
- | `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`) |
776
760
  | `print(...args)` | Available in `AxJSRuntime` when `outputMode: 'stdout'`; captured output appears in the function result |
777
761
  | Context variables | All fields listed in `contextFields` are available by name |
778
762
 
@@ -866,9 +850,9 @@ class MyBrowserInterpreter implements AxCodeRuntime {
866
850
  The `globals` object passed to `createSession` includes:
867
851
  - All context field values (by field name)
868
852
  - `llmQuery` function (supports both single and batched queries)
869
- - `submit(...args)` and `ask_clarification(...args)` completion functions
853
+ - `final(...args)` and `ask_clarification(...args)` completion functions
870
854
  - `agents` namespace object with child agent functions (e.g., `agents.summarize(...)`)
871
- - Tool functions as flat globals
855
+ - `<namespace>` objects containing agent functions (e.g., `globals.utils.search(...)`)
872
856
  - `print` function when supported by the runtime (for `AxJSRuntime`, set `outputMode: 'stdout'`)
873
857
 
874
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).
@@ -950,11 +934,22 @@ interface AxCodeSession {
950
934
  interface AxAgentConfig<IN, OUT> extends AxAgentOptions {
951
935
  ai?: AxAIService;
952
936
  agentIdentity?: { name: string; description: string };
953
- agents?: AxAgentic<IN, OUT>[];
954
- functions?: AxInputFunctionType;
955
937
  }
956
938
  ```
957
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
+
958
953
  ### `AxAgentOptions`
959
954
 
960
955
  Extends `AxProgramForwardOptions` (without `functions`) with:
@@ -963,17 +958,33 @@ Extends `AxProgramForwardOptions` (without `functions`) with:
963
958
  {
964
959
  debug?: boolean;
965
960
  contextFields: string[];
966
- sharedFields?: string[]; // Input fields to pass to direct child agents (one level)
967
- excludeSharedFields?: string[]; // Shared fields this agent should NOT receive from its parent
968
- sharedAgents?: AxAgentic[]; // Agents to add to direct child agents (one level)
969
- globalSharedFields?: string[]; // Input fields to pass to ALL descendants (recursive)
970
- globalSharedAgents?: AxAgentic[]; // Agents to add to ALL descendants (recursive)
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
+
971
982
  runtime?: AxCodeRuntime;
972
983
  maxLlmCalls?: number;
973
984
  maxRuntimeChars?: number;
974
985
  maxBatchedLlmQueryConcurrency?: number;
975
986
  maxTurns?: number;
976
- trajectoryPruning?: boolean; // @deprecated Use contextManagement.errorPruning
987
+ trajectoryPruning?: boolean; // @deprecated Use contextManagement.errorPruning
977
988
  contextManagement?: AxContextManagementConfig;
978
989
  actorFields?: string[];
979
990
  actorCallback?: (result: Record<string, unknown>) => void | Promise<void>;
@@ -981,27 +992,11 @@ Extends `AxProgramForwardOptions` (without `functions`) with:
981
992
  recursionOptions?: Partial<Omit<AxProgramForwardOptions, 'functions'>> & {
982
993
  maxDepth?: number; // Maximum recursion depth for llmQuery sub-agent calls (default: 2)
983
994
  };
984
- actorOptions?: Partial<AxProgramForwardOptions>; // Default forward options for Actor
985
- 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
986
997
  }
987
998
  ```
988
999
 
989
- ### `setActorDescription()`
990
-
991
- ```typescript
992
- public setActorDescription(additionalText: string): void
993
- ```
994
-
995
- Appends additional text to the Actor's RLM system prompt. The base prompt is preserved; the additional text is appended after it.
996
-
997
- ### `setResponderDescription()`
998
-
999
- ```typescript
1000
- public setResponderDescription(additionalText: string): void
1001
- ```
1002
-
1003
- Appends additional text to the Responder's RLM system prompt. The base prompt is preserved; the additional text is appended after it.
1004
-
1005
1000
  ### `stop()`
1006
1001
 
1007
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.13"
4
+ version: "19.0.2"
5
5
  ---
6
6
 
7
7
  # Ax Library (@ax-llm/ax) Usage Guide