axllm 23.0.2

Generated Ax runtime library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# Ax for Rust API Reference

This generated API reference is emitted by AxIR from compiler-owned metadata. Do not edit it by hand; change the AxIR generator and regenerate packages instead.

## Package

- Target: `rust`
- Package: `axllm`
- AxIR contract: `0.1`

## Signatures

Describe typed Ax inputs and outputs once, then reuse that shape for schemas, prompts, validation, tools, and structured results.

### `s`

Parse an Ax string signature into the target language signature object.

- Canonical Ax concept: `s`
- Kind: `function`
- Form: `s(spec: &str)`
- Returns: `AxResult<AxSignature>`

```rust
let sig = s("question:string -> answer:string")?;
```

### `f`

Build signatures and field types fluently when the target has a fluent helper.

- Canonical Ax concept: `f`
- Kind: `function`
- Form: `f().input(...).output(...).build()`
- Returns: `signature builder or field factory`
- Important options: input fields, output fields, field descriptions, constraints

### `AxSignature`

Parsed signature with input/output fields, descriptions, and JSON schema helpers.

- Canonical Ax concept: `AxSignature`
- Kind: `type`
- Form: `AxSignature`
- Returns: `signature object`
- Important options: inputs, outputs, description


## AxGen

Run structured generation with Core-owned prompts, tool loops, retries, streaming folds, traces, usage, examples, and field processors.

### `ax`

Create an AxGen program from a string or parsed signature.

- Canonical Ax concept: `ax`
- Kind: `function`
- Form: `ax(spec: &str)`
- Returns: `AxResult<AxGen>`
- Important options: functions, examples, demos, modelConfig, maxRetries, streaming assertions, field processors

```rust
let qa = ax("question:string -> answer:string")?;
```

### `AxGen`

Structured generation program with forward, streaming, optimization, trace, usage, and tool-call behavior.

- Canonical Ax concept: `AxGen`
- Kind: `type`
- Form: `AxGen`
- Returns: `program object`
- Important options: signature, functions, examples, demos, memory, prompt template


## AxAI

Call supported providers through the shared provider descriptor registry, scripted transports, routers, and balancers.

### `ai`

Create a provider client from a provider name and options.

- Canonical Ax concept: `ai`
- Kind: `function`
- Form: `ai(provider, options)`
- Returns: `AxResult<OpenAICompatibleClient>`
- Important options: api key, model, api URL, headers, transport

```rust
let client = ai("openai", json!({"apiKey": std::env::var("OPENAI_API_KEY")?}))?;
```

### `OpenAICompatibleClient`

OpenAI-compatible chat, stream, embedding, audio, and realtime provider boundary.

- Canonical Ax concept: `OpenAICompatibleClient`
- Kind: `type`
- Form: `OpenAICompatibleClient / ai(provider, options)`
- Returns: `provider client`
- Important options: api key, model, base URL, transport

### `OpenAIResponsesClient`

OpenAI Responses provider mapping using the same Core-owned request and response contract.

- Canonical Ax concept: `OpenAIResponsesClient`
- Kind: `type`
- Form: `OpenAIResponsesClient / ai(provider, options)`
- Returns: `provider client`
- Important options: api key, model, audio, realtime

### `GoogleGeminiClient`

Gemini provider mapping for chat, streaming, media, tools, embeddings, and usage normalization.

- Canonical Ax concept: `GoogleGeminiClient`
- Kind: `type`
- Form: `GoogleGeminiClient / ai(provider, options)`
- Returns: `provider client`
- Important options: api key, model, embed model

### `AnthropicClient`

Anthropic provider mapping for messages, thinking, cache control, streaming, and usage normalization.

- Canonical Ax concept: `AnthropicClient`
- Kind: `type`
- Form: `AnthropicClient / ai(provider, options)`
- Returns: `provider client`
- Important options: api key, model, thinking, cache control

### `AxBalancer`

Retry and route requests across multiple provider services while preserving Ax request shape.

- Canonical Ax concept: `AxBalancer`
- Kind: `type`
- Form: `AxBalancer`
- Returns: `AI service`
- Important options: services, retry policy, capability requirements

### `MultiServiceRouter`

Choose a service by capability or model routing policy.

- Canonical Ax concept: `MultiServiceRouter`
- Kind: `type`
- Form: `MultiServiceRouter`
- Returns: `AI service`
- Important options: services, routing

### `ProviderRouter`

Route provider requests to registered provider clients.

- Canonical Ax concept: `ProviderRouter`
- Kind: `type`
- Form: `ProviderRouter`
- Returns: `AI service`
- Important options: providers, routing, processing


## Agents And RLM

Run AxAgent through the RLM executor loop with stage instructions, validated evidence citations, persistent playbooks, and actor-code execution through an AxCodeRuntime session.

### `agent`

Create an AxAgent from a signature and agent/runtime options.

- Canonical Ax concept: `agent`
- Kind: `function`
- Form: `agent(spec: &str)`
- Returns: `AxResult<AxAgent>`
- Important options: name, description, runtime, maxSteps, context fields, discovery, recall, functions, citations, playbook, instruction, instructionAddenda

```rust
let helper = agent("query:string -> answer:string")?;
```

### `AxAgent`

RLM agent with Core-owned envelopes, state, traces, discovery, recall, delegation, validated citations, stage instructions, persistent run-end learning, and verified playbook evolution.

- Canonical Ax concept: `AxAgent`
- Kind: `type`
- Form: `AxAgent`
- Returns: `agent program`
- Important options: executor model, runtime, policy, context, optimizer metadata, citations, playbook


## Flow

Compose AxGen, AxAgent, and nested flows into a portable program graph.

### `flow`

Create an AxFlow program graph or compile the portable Mermaid shorthand.

- Canonical Ax concept: `flow`
- Kind: `function`
- Form: `flow(source) / flow_with_bindings(source, bindings)`
- Returns: `AxFlow`
- Important options: nodes, execute mappers, conditions, cache, returns, Mermaid roundtrip

```rust
let wf = flow("workflow");
```

### `AxFlow`

Workflow graph with Core-owned planning, cache keys, state merge, child aggregation, optimization, and returns projection.

- Canonical Ax concept: `AxFlow`
- Kind: `type`
- Form: `AxFlow`
- Returns: `flow program`
- Important options: steps, state, parallel groups, returns


## Tools

Expose host functions to AxGen and AxAgent with typed argument and return schemas.

### `tool`

Build a typed function tool. Rust uses `tool` because `fn` is reserved.

- Canonical Ax concept: `fn`
- Kind: `function`
- Form: `tool(name).description(...).arg(...).handler(...).build()`
- Returns: `ToolBuilder`
- Important options: name, description, args, returns, handler

```rust
let search = tool("search").description("Search docs").build();
```

### `Tool`

Callable tool descriptor with JSON-schema-compatible parameters and a host handler.

- Canonical Ax concept: `Tool`
- Kind: `type`
- Form: `Tool`
- Returns: `tool descriptor`
- Important options: parameters, returns, handler


## MCP

Use MCP clients and transports while keeping JSON-RPC lifecycle, tools, prompts, resources, OAuth, cancellation, and SSRF checks aligned.

### `AxMCPClient`

MCP client that lists tools/prompts/resources and converts MCP tools to Ax functions.

- Canonical Ax concept: `AxMCPClient`
- Kind: `type`
- Form: `AxMCPClient::new(transport, options)`
- Returns: `MCP client`
- Important options: transport, client info, roots, tool overrides

```rust
let client = AxMCPClient::new(transport, json!({}));
```

### `AxMCPStreamableHTTPTransport`

Streamable HTTP transport with session headers, OAuth options, and SSRF protection.

- Canonical Ax concept: `AxMCPStreamableHTTPTransport`
- Kind: `type`
- Form: `AxMCPStreamableHTTPTransport`
- Returns: `MCP transport`
- Important options: endpoint, headers, OAuth, SSRF protection

### `AxMCPStdioTransport`

Stdio transport with JSON-RPC framing for local MCP servers.

- Canonical Ax concept: `AxMCPStdioTransport`
- Kind: `type`
- Form: `AxMCPStdioTransport`
- Returns: `MCP transport`
- Important options: command, args, env


## Runtime Profiles

Run RLM actor code through the portable AxCodeRuntime and optional target-specific runtime profiles.

### `ProcessCodeRuntime`

Process/JSONL runtime adapter for actor-code sessions and runtime protocol tests.

- Canonical Ax concept: `ProcessCodeRuntime`
- Kind: `type`
- Form: `ProcessCodeRuntime::new(command)`
- Returns: `AxCodeRuntime`
- Important options: command, env, cwd, timeout

```rust
let runtime = ProcessCodeRuntime::new(vec!["node".into(), "runtime-server.mjs".into()]);
```

### `RuntimeCapabilities`

Runtime capability envelope visible to the agent runtime policy.

- Canonical Ax concept: `RuntimeCapabilities`
- Kind: `type`
- Form: `RuntimeCapabilities`
- Returns: `capability record`
- Important options: language, snapshot, patch, abort, usage instructions

### `RuntimeEnvelope`

Actor primitive envelope for final, clarification, discovery, recall, used, guidance, and runtime results.

- Canonical Ax concept: `RuntimeEnvelope`
- Kind: `type`
- Form: `RuntimeEnvelope`
- Returns: `runtime envelope`
- Important options: type, args, result, error

### `javascript-quickjs`

Optional runtime profile for javascript actor code.

- Canonical Ax concept: `runtime-profile:javascript-quickjs`
- Kind: `runtime-profile`
- Form: `tools/axir verify --targets rust --runtime-profiles javascript-quickjs`
- Returns: `AxCodeRuntime-compatible actor execution profile`
- Important options: actor language: javascript, support mode: embedded, dependency mode: optional-feature, feature gate: runtime-quickjs


## Optimizers

Optimize Ax programs through BootstrapFewShot -> GEPA composition and evolve program or agent playbooks through grounded, budgeted, rollback-safe learning.

### `optimize`

Convenience optimizer helper that composes AxBootstrapFewShot before AxGEPA and returns an artifact without applying final component changes.

- Canonical Ax concept: `optimize`
- Kind: `function`
- Form: `optimize(program, examples, options)`
- Returns: `AxResult<OptimizedArtifact>`
- Important options: student/client, teacher/reflection client, metric budget, bootstrap

```rust
let artifact = optimize(&mut qa, train, json!({"maxMetricCalls": 100}))?;
```

### `playbook`

Bind an ACE-backed playbook to a program; agents also expose an agent-bound playbook handle.

- Canonical Ax concept: `playbook`
- Kind: `function`
- Form: `playbook(program, student, teacher, options)`
- Returns: `AxPlaybook`
- Important options: student/client, teacher, seed snapshot, online updates, verification budget

```rust
let pb = playbook(program, student, None::<Rc<RefCell<OpenAICompatibleClient>>>, json!({}));
```

### `AxPlaybook`

Persistent playbook with render/update/snapshot operations and agent-bound verified evolve over train/validation task sets.

- Canonical Ax concept: `AxPlaybook`
- Kind: `type`
- Form: `AxPlaybook / agent.playbook(...)`
- Returns: `playbook handle`
- Important options: verify, minHeldInGain, epsilon, runsPerTask, maxMetricCalls, maxProposals

### `AxBootstrapFewShot`

Few-shot demonstration optimizer that selects successful evaluator rollouts before prompt/component evolution.

- Canonical Ax concept: `AxBootstrapFewShot`
- Kind: `type`
- Form: `AxBootstrapFewShot::new(options)`
- Returns: `optimizer engine`
- Important options: quality threshold, max demos, max rounds, batch size

```rust
let bootstrap = AxBootstrapFewShot::new(json!({"qualityThreshold": 0.7}));
```

### `AxGEPA`

Generated GEPA optimizer engine with Core-owned reflection, Pareto, bootstrap, and selector-state behavior.

- Canonical Ax concept: `AxGEPA`
- Kind: `type`
- Form: `AxGEPA::new(reflection, options)`
- Returns: `optimizer engine`
- Important options: reflection client, budget, metric, candidate count

```rust
let engine = AxGEPA::new(reflection_client, json!({}));
```

### `OptimizerEngine`

Optimizer boundary consumed by AxGen, AxAgent, and AxFlow optimization helpers.

- Canonical Ax concept: `OptimizerEngine`
- Kind: `interface`
- Form: `OptimizerEngine::optimize(request, evaluator)`
- Returns: `optimized artifact`
- Important options: request, evaluator

### `OptimizerEvaluator`

Evaluator callback boundary used by generated optimizers.

- Canonical Ax concept: `OptimizerEvaluator`
- Kind: `interface`
- Form: `OptimizerEvaluator::evaluate(request)`
- Returns: `score/evidence result`
- Important options: dataset rows, candidate map, evidence


## Errors And Values

Handle target-native errors and dynamic values at Ax host boundaries.

### `AxError`

Target-native error envelope for validation, provider, runtime, MCP, and optimizer failures.

- Canonical Ax concept: `AxError`
- Kind: `type`
- Form: `AxError with target-native error handling`
- Returns: `error`
- Important options: category, message, status, code, retryable

### `serde_json::Value`

Dynamic JSON-like value boundary used by generated package APIs, tools, providers, MCP, and runtime sessions.

- Canonical Ax concept: `Value`
- Kind: `type`
- Form: `serde_json::Value`
- Returns: `dynamic value`
- Important options: string, number, boolean, object, array, null