ax() API
Structured generation APIs for typed programs.
Most Used
ax
Create an AxGen program from a string or parsed signature.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | ax |
| API section | AxGen |
| Form | ax(signature, options=None) |
| Returns | AxGen |
Important Options
functionsexamplesdemossample countresult pickermodelConfigmaxRetriesstreaming assertionsfield processorscontrolasyncMode
Examples
qa = ax("question:string -> answer:string")AxGen
Structured generation program with indexed multi-sampling, winner selection, forward, streaming, optimization, trace, usage, and tool-call behavior.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxGen |
| API section | AxGen |
| Form | AxGen(signature, options=None) |
| Returns | program object |
Important Options
signaturefunctionsexamplesdemossample countresult pickermemoryprompt template
fn
Build a typed function tool. Rust uses tool because fn is reserved.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | fn |
| API section | Tools |
| Form | fn(name).description(...).arg(...).handler(...).build() |
| Returns | tool builder or Tool |
Important Options
namedescriptionargsreturnshandlerexecution: blocking or backgroundcancellation-aware handler
Examples
search = fn("search").description("Search docs").arg("query", f.string()).build()Advanced / internals / full reference
run_control
Create a controller for scoped steering, reasoning updates, cancellation, and queued/applied lifecycle events. Pass it through forward options.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | run_control |
| API section | AxGen |
| Form | run_control() |
| Returns | AxRunControl |
Examples
control = run_control()AxRunControl
Run control shared by active and future descendant programs. Cancellation reports unresolved work and does not undo external effects.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxRunControl |
| API section | AxGen |
| Form | AxRunControl |
| Returns | run controller |
Important Options
steerthinking token budgettarget pathabortevent listener
Callable[[str, dict | None], dict | None]
TypeScript’s cachingFunction: read and store finished AxGen outputs by key. The forward call’s function comes first, then the program’s, then the process-wide one, and a run control skips the cache.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxCachingFunction |
| API section | AxGen |
| Form | caching_function(key, output=None) |
| Returns | stored output or miss |
Important Options
readstoreSHA-256 keystreamed hit as one delta
Examples
qa = ax("question:string -> answer:string", {"caching_function": cache})set_caching_function
Register, replace, or clear the process-wide AxGen caching function.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | set_caching_function |
| API section | AxGen |
| Form | set_caching_function(fn) |
| Returns | void |
Important Options
caching functionclear
Examples
set_caching_function(cache)Tool
Callable tool descriptor with JSON-schema-compatible parameters and a host handler.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | Tool |
| API section | Tools |
| Form | Tool(name, description, parameters, handler) |
| Returns | tool descriptor |
Important Options
parametersreturnshandler
Full Reference
Open the full Python reference. This page highlights the ax symbols most relevant to everyday use.