@ax-llm/ax 17.0.9 → 17.0.11
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/index.cjs +326 -189
- package/index.cjs.map +1 -1
- package/index.d.cts +17 -1
- package/index.d.ts +17 -1
- package/index.global.js +376 -239
- package/index.global.js.map +1 -1
- package/index.js +325 -188
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/ax-agent.md +44 -3
- package/skills/ax-llm.md +1 -1
package/package.json
CHANGED
package/skills/ax-agent.md
CHANGED
|
@@ -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, smart model routing, RLM mode, stopping agents, or composing multi-agent hierarchies.
|
|
4
|
-
version: "17.0.
|
|
4
|
+
version: "17.0.11"
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# AxAgent Guide (@ax-llm/ax)
|
|
@@ -477,9 +477,43 @@ The LLM's typical workflow:
|
|
|
477
477
|
|-----|-------------|
|
|
478
478
|
| `await llmQuery(query, context?)` | Ask a sub-LM a question, optionally with a context string. Returns a string. Oversized context is truncated to `maxRuntimeChars` |
|
|
479
479
|
| `await llmQuery([{ query, context? }, ...])` | Run multiple sub-LM queries in parallel. Returns string[]. Failed items return `[ERROR] ...` |
|
|
480
|
-
| `print(...args)` |
|
|
480
|
+
| `print(...args)` | Available in `AxJSRuntime` when `outputMode: 'stdout'`; captured output appears in the function result |
|
|
481
481
|
| Context variables | All fields listed in `contextFields` are available by name |
|
|
482
482
|
|
|
483
|
+
By default, `AxJSRuntime` uses `outputMode: 'stdout'`, where visible output comes from `console.log(...)`, `print(...)`, and other captured stdout lines.
|
|
484
|
+
|
|
485
|
+
### Session State and `await`
|
|
486
|
+
|
|
487
|
+
`AxJSRuntime` state is session-scoped. Values survive across `execute()` calls only while you keep using the same session.
|
|
488
|
+
|
|
489
|
+
- `mode: 'inline'` and `mode: 'function'` in RLM both run in a persistent runtime session.
|
|
490
|
+
- `runtime.toFunction()` is different: it creates a new session per tool call, then closes it, so state does not persist across calls.
|
|
491
|
+
|
|
492
|
+
When code contains `await`, the runtime compiles it as an async function so top-level `await` works. In that async path, local declarations (`const`/`let`/`var`) are function-scoped and should not be relied on for cross-call state.
|
|
493
|
+
|
|
494
|
+
Prefer one of these patterns for durable state:
|
|
495
|
+
|
|
496
|
+
```javascript
|
|
497
|
+
// Pattern 1: Explicit global
|
|
498
|
+
globalThis.state = await getState();
|
|
499
|
+
globalThis.state.x += 1;
|
|
500
|
+
return globalThis.state;
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
```javascript
|
|
504
|
+
// Pattern 2: Shared object passed in globals/context
|
|
505
|
+
state.x += 1;
|
|
506
|
+
return state;
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
This may appear to work in some cases:
|
|
510
|
+
|
|
511
|
+
```javascript
|
|
512
|
+
state = await getState(); // no let/const/var
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
but `globalThis.state = ...` (or mutating a shared `state` object) is the recommended explicit pattern.
|
|
516
|
+
|
|
483
517
|
### Error handling in the code interpreter
|
|
484
518
|
|
|
485
519
|
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:
|
|
@@ -512,6 +546,10 @@ import type { AxCodeRuntime, AxCodeSession } from '@ax-llm/ax';
|
|
|
512
546
|
class MyBrowserInterpreter implements AxCodeRuntime {
|
|
513
547
|
readonly language = 'JavaScript';
|
|
514
548
|
|
|
549
|
+
getUsageInstructions?(): string {
|
|
550
|
+
return 'Runtime-specific guidance for writing code in this environment.';
|
|
551
|
+
}
|
|
552
|
+
|
|
515
553
|
createSession(globals?: Record<string, unknown>): AxCodeSession {
|
|
516
554
|
return {
|
|
517
555
|
async execute(code: string): Promise<unknown> {
|
|
@@ -528,7 +566,9 @@ class MyBrowserInterpreter implements AxCodeRuntime {
|
|
|
528
566
|
The `globals` object passed to `createSession` includes:
|
|
529
567
|
- All context field values (by field name)
|
|
530
568
|
- `llmQuery` function (supports both single and batched queries)
|
|
531
|
-
- `print` function
|
|
569
|
+
- `print` function when supported by the runtime (for `AxJSRuntime`, set `outputMode: 'stdout'`)
|
|
570
|
+
|
|
571
|
+
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).
|
|
532
572
|
|
|
533
573
|
### RLM with Streaming
|
|
534
574
|
|
|
@@ -559,6 +599,7 @@ interface AxRLMConfig {
|
|
|
559
599
|
```typescript
|
|
560
600
|
interface AxCodeRuntime {
|
|
561
601
|
readonly language: string;
|
|
602
|
+
getUsageInstructions?(): string;
|
|
562
603
|
createSession(globals?: Record<string, unknown>): AxCodeSession;
|
|
563
604
|
}
|
|
564
605
|
```
|
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: "17.0.
|
|
4
|
+
version: "17.0.11"
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Ax Library (@ax-llm/ax) Usage Guide
|