@ax-llm/ax 19.0.16 → 19.0.17
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 +367 -255
- package/index.cjs.map +1 -1
- package/index.d.cts +681 -558
- package/index.d.ts +681 -558
- package/index.global.js +370 -258
- package/index.global.js.map +1 -1
- package/index.js +379 -267
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/ax-agent.md +77 -7
- package/skills/ax-ai.md +245 -0
- package/skills/ax-flow.md +402 -0
- package/skills/ax-gen.md +323 -0
- package/skills/ax-gepa.md +244 -0
- package/skills/ax-learn.md +268 -0
- package/skills/ax-llm.md +150 -1675
- package/skills/ax-signature.md +192 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ax-signature
|
|
3
|
+
description: This skill helps an LLM generate correct DSPy signature code using @ax-llm/ax. Use when the user asks about signatures, s(), f(), field types, string syntax, fluent builder API, validation constraints, or type-safe inputs/outputs.
|
|
4
|
+
version: "19.0.17"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Ax Signature Reference
|
|
8
|
+
|
|
9
|
+
## Signature Syntax
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
[description] input1:type, input2:type -> output1:type, output2:type
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Field Types
|
|
16
|
+
|
|
17
|
+
| Type | Syntax | TypeScript | Example |
|
|
18
|
+
|------|--------|-----------|---------|
|
|
19
|
+
| String | `:string` | `string` | `userName:string` |
|
|
20
|
+
| Number | `:number` | `number` | `score:number` |
|
|
21
|
+
| Boolean | `:boolean` | `boolean` | `isValid:boolean` |
|
|
22
|
+
| JSON | `:json` | `any` | `metadata:json` |
|
|
23
|
+
| Date | `:date` | `Date` | `birthDate:date` |
|
|
24
|
+
| DateTime | `:datetime` | `Date` | `timestamp:datetime` |
|
|
25
|
+
| Image | `:image` | `{mimeType, data}` | `photo:image` (input only) |
|
|
26
|
+
| Audio | `:audio` | `{format?, data}` | `recording:audio` (input only) |
|
|
27
|
+
| File | `:file` | `{mimeType, data}` | `document:file` (input only) |
|
|
28
|
+
| URL | `:url` | `string` | `website:url` |
|
|
29
|
+
| Code | `:code` | `string` | `pythonScript:code` |
|
|
30
|
+
| Class | `:class "a, b, c"` | `"a" \| "b" \| "c"` | `mood:class "happy, sad"` |
|
|
31
|
+
|
|
32
|
+
## Arrays, Optional, and Internal Fields
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
'tags:string[] -> processedTags:string[]' // arrays
|
|
36
|
+
'query:string, context?:string -> response:string' // optional with ?
|
|
37
|
+
'problem:string -> reasoning!:string, solution:string' // internal with !
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Three Ways to Create Signatures
|
|
41
|
+
|
|
42
|
+
### 1. String-Based (Recommended for simple cases)
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { ax, s } from '@ax-llm/ax';
|
|
46
|
+
const gen = ax('input:string -> output:string');
|
|
47
|
+
const sig = s('query:string -> response:string');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Pure Fluent Builder API
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { f } from '@ax-llm/ax';
|
|
54
|
+
const sig = f()
|
|
55
|
+
.input('userMessage', f.string('User input'))
|
|
56
|
+
.input('contextData', f.string('Additional context').optional())
|
|
57
|
+
.input('tags', f.string('Keywords').array())
|
|
58
|
+
.output('responseText', f.string('AI response'))
|
|
59
|
+
.output('confidenceScore', f.number('Confidence 0-1'))
|
|
60
|
+
.output('debugInfo', f.string('Debug info').internal())
|
|
61
|
+
.build();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 3. Hybrid
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { s, f } from '@ax-llm/ax';
|
|
68
|
+
const sig = s('base:string -> result:string')
|
|
69
|
+
.appendInputField('extra', f.json('Metadata').optional())
|
|
70
|
+
.appendOutputField('score', f.number('Quality score'));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Fluent API Reference
|
|
74
|
+
|
|
75
|
+
Type creators:
|
|
76
|
+
- `f.string(desc)`, `f.number(desc)`, `f.boolean(desc)`, `f.json(desc)`
|
|
77
|
+
- `f.image(desc)`, `f.audio(desc)`, `f.file(desc)`, `f.url(desc)`
|
|
78
|
+
- `f.email(desc)`, `f.date(desc)`, `f.datetime(desc)`
|
|
79
|
+
- `f.class(['a','b','c'], desc)`, `f.code(desc)`
|
|
80
|
+
- `f.object({ field: f.string() }, desc)`
|
|
81
|
+
|
|
82
|
+
Chainable modifiers (method chaining only, no nesting):
|
|
83
|
+
- `.optional()` - make field optional
|
|
84
|
+
- `.array()` / `.array('list description')` - make field an array
|
|
85
|
+
- `.internal()` - output only, hidden from final output
|
|
86
|
+
- `.cache()` - input only, mark for prompt caching
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// Correct: pure fluent chaining
|
|
90
|
+
f.string('description').optional().array()
|
|
91
|
+
f.string('context').cache().optional()
|
|
92
|
+
f.object({ field: f.string() }, 'item desc').array('list desc')
|
|
93
|
+
|
|
94
|
+
// Wrong: nested function calls (removed)
|
|
95
|
+
f.array(f.string('description')) // REMOVED
|
|
96
|
+
f.optional(f.string('description')) // REMOVED
|
|
97
|
+
f.internal(f.string('description')) // REMOVED
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Validation Constraints
|
|
101
|
+
|
|
102
|
+
### String Constraints
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
f.string('username').min(3).max(20)
|
|
106
|
+
f.string('email').email()
|
|
107
|
+
f.string('website').url()
|
|
108
|
+
f.string('birthDate').date()
|
|
109
|
+
f.string('timestamp').datetime()
|
|
110
|
+
f.string('pattern').regex('^[A-Z0-9]')
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Number Constraints
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
f.number('age').min(18).max(120)
|
|
117
|
+
f.number('score').min(0).max(100)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Complete Validation Example
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const sig = f()
|
|
124
|
+
.input('formData', f.string('Raw form data'))
|
|
125
|
+
.output('user', f.object({
|
|
126
|
+
username: f.string('Username').min(3).max(20),
|
|
127
|
+
email: f.string('Email').email(),
|
|
128
|
+
age: f.number('Age').min(18).max(120),
|
|
129
|
+
bio: f.string('Bio').max(500).optional(),
|
|
130
|
+
website: f.string('Website').url().optional(),
|
|
131
|
+
tags: f.string('Tag').min(2).max(30).array()
|
|
132
|
+
}, 'User profile'))
|
|
133
|
+
.build();
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Cached Input Fields
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
const sig = f()
|
|
140
|
+
.input('staticContext', f.string('Context').cache())
|
|
141
|
+
.input('userQuery', f.string('Dynamic query'))
|
|
142
|
+
.output('answer', f.string('Response'))
|
|
143
|
+
.build();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Field Naming Rules
|
|
147
|
+
|
|
148
|
+
Good: `userQuestion`, `customerEmail`, `analysisResult`, `confidenceScore`
|
|
149
|
+
Bad: `text`, `data`, `input`, `output`, `a`, `x`, `val` (too generic), `1field` (starts with number)
|
|
150
|
+
|
|
151
|
+
## Media Type Restrictions
|
|
152
|
+
|
|
153
|
+
- Media types (image, audio, file) are **top-level input fields only**
|
|
154
|
+
- Cannot be nested in objects
|
|
155
|
+
- Cannot be output fields
|
|
156
|
+
|
|
157
|
+
## Common Patterns
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Chain of Thought
|
|
161
|
+
'problem:string -> reasoning!:string, solution:string'
|
|
162
|
+
|
|
163
|
+
// Classification
|
|
164
|
+
'email:string -> priority:class "urgent, normal, low"'
|
|
165
|
+
|
|
166
|
+
// Multi-modal
|
|
167
|
+
'imageData:image, question?:string -> description:string, objects:string[]'
|
|
168
|
+
|
|
169
|
+
// Data Extraction
|
|
170
|
+
'invoiceText:string -> invoiceNumber:string, totalAmount:number, lineItems:json[]'
|
|
171
|
+
|
|
172
|
+
// With description
|
|
173
|
+
'"Answer TypeScript questions" question:string -> answer:string, confidence:number'
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Critical Rules
|
|
177
|
+
|
|
178
|
+
- Use `f()` fluent builder, NOT nested `f.array(f.string())` -- those are removed.
|
|
179
|
+
- Field names must be descriptive (not generic like `text`, `data`, `input`).
|
|
180
|
+
- Media types are input-only, top-level only.
|
|
181
|
+
- `.internal()` is output-only (for chain-of-thought reasoning).
|
|
182
|
+
- `.cache()` is input-only (for prompt caching).
|
|
183
|
+
- Validation errors trigger auto-retry with correction feedback.
|
|
184
|
+
- `f.email()`, `f.url()`, `f.date()`, `f.datetime()` are shorthand for `f.string().email()` etc.
|
|
185
|
+
|
|
186
|
+
## Examples
|
|
187
|
+
|
|
188
|
+
Fetch these for full working code:
|
|
189
|
+
|
|
190
|
+
- [Fluent Signature](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/fluent-signature-example.ts) — fluent f() API
|
|
191
|
+
- [Structured Output](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/structured_output.ts) — structured output with validation
|
|
192
|
+
- [Debug Schema](https://raw.githubusercontent.com/ax-llm/ax/refs/heads/main/src/examples/debug_schema.ts) — JSON schema validation
|