@botpress/adk-cli 1.19.0-beta.3 → 1.19.0-beta.5
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/assets/ui-dist/assets/{index-CSTz-oTK.js → index-B3b7PPgV.js} +4 -4
- package/{dist/index-DNqXHLNi-27nvpkee.js → assets/ui-dist/assets/index-BESZeTO5.js} +2 -2
- package/{dist/index-DAztRXeA-vr85xnxs.css → assets/ui-dist/assets/index-DIFGtVmI.css} +1 -1
- package/{dist/index-DfjXY3Oo-szsanhnt.js → assets/ui-dist/assets/index-a3ZL0_Jr.js} +2 -2
- package/assets/ui-dist/index.html +2 -2
- package/dist/{README-wjb7z7f0.md → README-824wa4jj.md} +1 -1
- package/dist/SKILL-75ym6tcj.md +257 -0
- package/dist/SKILL-chnwzmt1.md +548 -0
- package/dist/SKILL-d4bs53y3.md +244 -0
- package/dist/SKILL-h4b2f1n9.md +114 -0
- package/dist/SKILL-hbw5nt95.md +111 -0
- package/dist/actions-h7hxxvxr.md +823 -0
- package/dist/adk-build-emhwd0tg.md +39 -0
- package/dist/adk-debug-yrrdtpmb.md +23 -0
- package/dist/adk-dev-console-7z9rtjpy.md +17 -0
- package/dist/adk-document-ras6zzzh.md +68 -0
- package/dist/adk-eval-vx76dwq0.md +17 -0
- package/dist/adk-explain-fcsaw852.md +22 -0
- package/dist/adk-init-9kmxmbbe.md +30 -0
- package/dist/adk-ship-dybzn884.md +29 -0
- package/dist/adk-test-xq67savs.md +27 -0
- package/dist/adk-validate-1p4skv4m.md +31 -0
- package/dist/advanced-patterns-z86m9h1a.md +669 -0
- package/dist/agent-config-1aqvkrgf.md +450 -0
- package/dist/agent-steps-zj4c1n9t.md +115 -0
- package/dist/agent0-assets/skills/adk/SKILL.md +5 -5
- package/dist/agent0-assets/skills/adk/references/cli.md +265 -24
- package/dist/agent0-assets/skills/adk-debugger/SKILL.md +5 -5
- package/dist/agent0-assets/skills/adk-debugger/references/common-failures.md +1 -1
- package/dist/agent0-assets/skills/adk-debugger/references/debug-workflow.md +3 -3
- package/dist/agent0-assets/skills/adk-debugger/references/traces-and-logs.md +15 -7
- package/dist/assets-q7jt8r2q.md +237 -0
- package/dist/autonomous-execution-fymc12e5.md +747 -0
- package/dist/cli-c31e06yr.md +1334 -0
- package/dist/cli.js +963 -548
- package/dist/commands.json +24 -3
- package/dist/common-failures-ht29w2db.md +231 -0
- package/dist/component-registry-bbpw0see.md +43 -0
- package/dist/context-api-760cvh0h.md +461 -0
- package/dist/conversation-analysis-8ka4nrm4.md +420 -0
- package/dist/conversation-lifecycle-4seqqjc1.md +311 -0
- package/dist/conversations-gwfvxaee.md +1111 -0
- package/dist/custom-components-y5wdgpey.md +167 -0
- package/dist/debug-workflow-vz84q80v.md +239 -0
- package/dist/desk-k54ktvsd.md +852 -0
- package/dist/doc-standards-ck6ax2jd.md +124 -0
- package/dist/eval-format-7n9brja4.md +354 -0
- package/dist/evals-y1zcr1mc.md +11 -0
- package/dist/explain-config-1yaq3zzd.md +424 -0
- package/dist/files-dzt0wxn3.md +918 -0
- package/dist/{index-gqxgqnyz.html → index-3t354nbw.html} +2 -2
- package/dist/{index-CSTz-oTK-mdfh47r8.js → index-B3b7PPgV-zetkb01w.js} +4 -4
- package/{assets/ui-dist/assets/index-DNqXHLNi.js → dist/index-BESZeTO5-2rpmcefa.js} +2 -2
- package/{assets/ui-dist/assets/index-DAztRXeA.css → dist/index-DIFGtVmI-d4dhjg97.css} +1 -1
- package/{assets/ui-dist/assets/index-DfjXY3Oo.js → dist/index-a3ZL0_Jr-q145h35p.js} +2 -2
- package/dist/integration-actions-xang7tma.md +659 -0
- package/dist/integrations-k5ss07f4.md +266 -0
- package/dist/interfaces-6t0bpxs4.md +97 -0
- package/dist/knowledge-bases-20rg8p5c.md +456 -0
- package/dist/llm-debugging-76ng8rzm.md +209 -0
- package/dist/mcp-server-n1asyzhv.md +112 -0
- package/dist/messages-gkkg0b54.md +769 -0
- package/dist/model-configuration-f273kgd0.md +201 -0
- package/dist/multi-agent-dashboard-1mdfjdts.md +70 -0
- package/dist/pages-xn18xn73.md +273 -0
- package/dist/patterns-mistakes-5vb99dhf.md +469 -0
- package/dist/plugins-ttnx8f49.md +280 -0
- package/dist/tables-x45t36dd.md +1136 -0
- package/dist/tags-46td3qrg.md +516 -0
- package/dist/test-patterns-hj47w4nc.md +355 -0
- package/dist/testing-workflow-2vkp932f.md +225 -0
- package/dist/tools-wk7bq24z.md +581 -0
- package/dist/trace-summarization-hdyx1c2e.md +313 -0
- package/dist/traces-and-logs-f2kjfh19.md +203 -0
- package/dist/triggers-4j2cc86x.md +719 -0
- package/dist/ui-server-entry.js +977 -162
- package/dist/workflow-steps-mrdrf1c5.md +851 -0
- package/dist/workflows-gadx3s69.md +1408 -0
- package/dist/zai-agent-reference-e6644aad.md +454 -0
- package/dist/zai-complete-guide-mnna5d6f.md +1408 -0
- package/package.json +4 -4
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# ZAI Reference for AI Agents
|
|
2
|
+
|
|
3
|
+
ZAI is pre-configured in your ADK environment. Use `adk.zai.*` to access LLM operations with automatic type safety. Import `adk` from `@botpress/runtime`.
|
|
4
|
+
|
|
5
|
+
## Core Operations
|
|
6
|
+
|
|
7
|
+
### `zai.extract(input, schema)`
|
|
8
|
+
|
|
9
|
+
Extract structured data from any input using Zod schema. Auto-handles large documents via chunking.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
await zai.extract(
|
|
13
|
+
"John is 30",
|
|
14
|
+
z.object({ name: z.string(), age: z.number() }),
|
|
15
|
+
);
|
|
16
|
+
// → { name: 'John', age: 30 }
|
|
17
|
+
|
|
18
|
+
await zai.extract(
|
|
19
|
+
emails,
|
|
20
|
+
z.array(z.object({ from: z.string(), subject: z.string() })),
|
|
21
|
+
);
|
|
22
|
+
// → [{ from: 'alice@example.com', subject: 'Meeting' }, ...]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### `zai.check(input, condition)`
|
|
26
|
+
|
|
27
|
+
Boolean verification using natural language.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
await zai.check("Buy cheap pills!", "is spam"); // → true
|
|
31
|
+
await zai.check(code, "contains SQL injection vulnerability"); // → boolean
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### `zai.label(input, criteria)`
|
|
35
|
+
|
|
36
|
+
Apply multiple boolean labels simultaneously.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
await zai.label(customerEmail, {
|
|
40
|
+
spam: "is spam",
|
|
41
|
+
urgent: "requires immediate response",
|
|
42
|
+
complaint: "expresses dissatisfaction",
|
|
43
|
+
});
|
|
44
|
+
// → { spam: false, urgent: true, complaint: true }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `zai.rewrite(input, instruction)`
|
|
48
|
+
|
|
49
|
+
Transform text per instruction.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
await zai.rewrite("hey wassup", "make professional"); // → 'Hello, how are you?'
|
|
53
|
+
await zai.rewrite(html, "convert to markdown");
|
|
54
|
+
await zai.rewrite(text, "translate to French");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### `zai.filter(array, condition)`
|
|
58
|
+
|
|
59
|
+
Filter arrays with natural language.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
await zai.filter(users, "have purchased in last 30 days");
|
|
63
|
+
await zai.filter([1, 2, 3, 4, 5], "are prime numbers"); // → [2,3,5]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `zai.text(prompt)`
|
|
67
|
+
|
|
68
|
+
Generate text from prompt.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
await zai.text("Write a regex for email validation");
|
|
72
|
+
await zai.text("SQL query to find duplicate records");
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `zai.summarize(input)`
|
|
76
|
+
|
|
77
|
+
Create intelligent summary. Handles any size via auto-chunking.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
await zai.summarize(longDocument);
|
|
81
|
+
await zai.summarize(chatHistory, {
|
|
82
|
+
length: 200,
|
|
83
|
+
prompt: "focus on decisions made",
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### `zai.answer(documents, question)`
|
|
88
|
+
|
|
89
|
+
Answer questions from documents with citations and intelligent edge case handling. Returns different response types based on question quality and available information.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const docs = [
|
|
93
|
+
"Botpress was founded in 2016.",
|
|
94
|
+
"The company is based in Quebec, Canada.",
|
|
95
|
+
"Botpress provides an AI agent platform.",
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const result = await zai.answer(docs, "When was Botpress founded?");
|
|
99
|
+
if (result.type === "answer") {
|
|
100
|
+
console.log(result.answer); // "Botpress was founded in 2016."
|
|
101
|
+
console.log(result.citations); // [{ offset: 30, item: docs[0], snippet: '...' }]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Handle different response types
|
|
105
|
+
switch (result.type) {
|
|
106
|
+
case "answer": // Has answer and citations
|
|
107
|
+
case "ambiguous": // Multiple interpretations, has follow_up question
|
|
108
|
+
case "out_of_topic": // Question unrelated to documents
|
|
109
|
+
case "invalid_question": // Malformed or unclear question
|
|
110
|
+
case "missing_knowledge": // Insufficient information
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `zai.rate(items, instructions)`
|
|
115
|
+
|
|
116
|
+
Rate array items on a 1-5 scale. Returns single score or multiple criteria scores.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// Single criterion (returns number 1-5)
|
|
120
|
+
await zai.rate(customerEmails, "urgency level");
|
|
121
|
+
// → [4, 2, 5, 1, 3]
|
|
122
|
+
|
|
123
|
+
// Multiple criteria (returns scores object)
|
|
124
|
+
await zai.rate(products, {
|
|
125
|
+
quality: "product build quality",
|
|
126
|
+
value: "price to performance ratio",
|
|
127
|
+
design: "aesthetic appeal",
|
|
128
|
+
});
|
|
129
|
+
// → [{ quality: 5, value: 4, design: 5, total: 14 }, ...]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `zai.sort(items, instructions)`
|
|
133
|
+
|
|
134
|
+
Sort array based on natural language instructions.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
await zai.sort(tickets, "from least urgent to most urgent");
|
|
138
|
+
await zai.sort(products, "by price, cheapest first");
|
|
139
|
+
await zai.sort(emails, "prioritize: open old items highest");
|
|
140
|
+
// Returns sorted array directly
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `zai.group(items, options)`
|
|
144
|
+
|
|
145
|
+
Group array elements based on natural language criteria.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
await zai.group(tickets, {
|
|
149
|
+
instructions: "group by issue type and priority",
|
|
150
|
+
});
|
|
151
|
+
// → [
|
|
152
|
+
// { id: 'bugs', label: 'Bug Reports', elements: [...] },
|
|
153
|
+
// { id: 'features', label: 'Feature Requests', elements: [...] }
|
|
154
|
+
// ]
|
|
155
|
+
|
|
156
|
+
// With initial groups
|
|
157
|
+
await zai.group(emails, {
|
|
158
|
+
instructions: "categorize emails",
|
|
159
|
+
initialGroups: [
|
|
160
|
+
{ id: "urgent", label: "Urgent" },
|
|
161
|
+
{ id: "spam", label: "Spam" },
|
|
162
|
+
],
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### `zai.patch(files, instructions)`
|
|
167
|
+
|
|
168
|
+
Patch code files using natural language instructions. Uses efficient micropatch protocol.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const files = [
|
|
172
|
+
{
|
|
173
|
+
path: "src/hello.ts",
|
|
174
|
+
name: "hello.ts",
|
|
175
|
+
content: 'console.log("Hello World")',
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
const patched = await zai.patch(files, 'change message to "Hi World"');
|
|
180
|
+
// → [{ path: 'src/hello.ts', content: 'console.log("Hi World")', patch: '...' }]
|
|
181
|
+
|
|
182
|
+
// Works with multiple files
|
|
183
|
+
await zai.patch(files, "add JSDoc comments to all functions");
|
|
184
|
+
await zai.patch(files, "remove all debug code");
|
|
185
|
+
await zai.patch(files, "update version to 2.0.0 in all config files");
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Advanced Usage
|
|
189
|
+
|
|
190
|
+
### `zai.with(options)`
|
|
191
|
+
|
|
192
|
+
Create a new instance with modified configuration.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const creativeZai = zai.with({ temperature: 0.9 });
|
|
196
|
+
const fastZai = zai.with({ modelId: "fast" });
|
|
197
|
+
const preciseZai = zai.with({ modelId: "best" }).learn("extraction-task");
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### `zai.learn(taskId)`
|
|
201
|
+
|
|
202
|
+
Enable learning for repetitive tasks. Caches exact matches, uses approved examples.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const smartZai = zai.learn("invoice-parsing");
|
|
206
|
+
await smartZai.extract(invoice, invoiceSchema); // Learns patterns over time
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Response Methods
|
|
210
|
+
|
|
211
|
+
All operations return a Response object:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const result = await zai.check(text, "is positive"); // Simple boolean
|
|
215
|
+
const { value, explanation } = await result.full(); // Detailed result
|
|
216
|
+
const { tokens, cost } = await result.usage(); // Usage metrics
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Options (all operations)
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
await zai.extract(input, schema, {
|
|
223
|
+
instructions: "Focus on financial data only",
|
|
224
|
+
strict: false, // Allow partial matches
|
|
225
|
+
chunkLength: 8000, // For large docs
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Quick Patterns
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
// Validate and extract
|
|
233
|
+
if (await zai.check(input, "is valid JSON")) {
|
|
234
|
+
const data = await zai.extract(input, schema);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Multi-step processing
|
|
238
|
+
const clean = await zai.rewrite(userInput, "remove profanity");
|
|
239
|
+
const translated = await zai.rewrite(clean, "translate to Spanish");
|
|
240
|
+
|
|
241
|
+
// Conditional filtering
|
|
242
|
+
const urgentTickets = await zai.filter(
|
|
243
|
+
tickets,
|
|
244
|
+
"require response within 1 hour",
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
// Smart extraction with learning
|
|
248
|
+
const parser = zai.learn("resume-parser");
|
|
249
|
+
const candidate = await parser.extract(resume, candidateSchema);
|
|
250
|
+
|
|
251
|
+
// Question answering with citations
|
|
252
|
+
const result = await zai.answer(knowledgeBase, userQuestion);
|
|
253
|
+
if (result.type === "answer") {
|
|
254
|
+
return { answer: result.answer, sources: result.citations };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Rate and sort workflow
|
|
258
|
+
const rated = await zai.rate(items, "quality score");
|
|
259
|
+
const sorted = await zai.sort(items, "by quality, best first");
|
|
260
|
+
|
|
261
|
+
// Group and process
|
|
262
|
+
const groups = await zai.group(tickets, {
|
|
263
|
+
instructions: "by priority and category",
|
|
264
|
+
});
|
|
265
|
+
for (const group of groups) {
|
|
266
|
+
await processGroup(group.label, group.elements);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Automated code modifications
|
|
270
|
+
const updatedFiles = await zai.patch(sourceFiles, "add TypeScript types");
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Everyday Problems Zai Solves
|
|
274
|
+
|
|
275
|
+
### Parsing Unstructured Input into Structured Data
|
|
276
|
+
|
|
277
|
+
A user sends "I'm Jane, I work at Acme Corp, my email is jane@acme.com and I need help with billing". Instead of regex or manual parsing:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
const contact = await zai.extract(message, z.object({
|
|
281
|
+
name: z.string(),
|
|
282
|
+
company: z.string(),
|
|
283
|
+
email: z.string(),
|
|
284
|
+
topic: z.string(),
|
|
285
|
+
}));
|
|
286
|
+
// → { name: 'Jane', company: 'Acme Corp', email: 'jane@acme.com', topic: 'billing' }
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Triaging Support Messages
|
|
290
|
+
|
|
291
|
+
Incoming messages need routing to the right team without building a classifier from scratch:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
const triage = await zai.label(message, {
|
|
295
|
+
urgent: "needs response within 1 hour",
|
|
296
|
+
billing: "related to payments or invoices",
|
|
297
|
+
technical: "related to bugs or technical issues",
|
|
298
|
+
churn_risk: "user is frustrated or threatening to leave",
|
|
299
|
+
});
|
|
300
|
+
// → { urgent: true, billing: true, technical: false, churn_risk: true }
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Making User Content Presentable
|
|
304
|
+
|
|
305
|
+
User-generated text needs to go into a report or external system:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
const cleaned = await zai.rewrite(userMessage, "fix grammar and spelling, keep the meaning");
|
|
309
|
+
const translated = await zai.rewrite(userMessage, "translate to French, keep a professional tone");
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Answering Questions from a Knowledge Base
|
|
313
|
+
|
|
314
|
+
A user asks a question and you have docs to search through — but you need citations and graceful handling when the answer isn't there:
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
const result = await zai.answer(kbDocuments, userQuestion);
|
|
318
|
+
if (result.type === "answer") {
|
|
319
|
+
return `${result.answer}\n\nSources: ${result.citations.map(c => c.snippet).join(", ")}`;
|
|
320
|
+
} else if (result.type === "missing_knowledge") {
|
|
321
|
+
return "I don't have enough information to answer that. Let me connect you with a human.";
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Prioritizing a Queue
|
|
326
|
+
|
|
327
|
+
A support queue has 50 tickets and the agent needs to work the most urgent ones first:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
// Score tickets, then sort by those scores
|
|
331
|
+
const scored = await zai.rate(tickets, "customer impact and time sensitivity");
|
|
332
|
+
// scored: [4, 2, 5, 1, 3] — one score per ticket
|
|
333
|
+
|
|
334
|
+
// Or sort directly when you only need ordering
|
|
335
|
+
const sorted = await zai.sort(tickets, "most urgent and highest impact first");
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Pre-screening Before Human Review
|
|
339
|
+
|
|
340
|
+
Filter out irrelevant items before a human sees them:
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
const relevant = await zai.filter(applications, "meet minimum requirements: 3+ years experience, relevant degree");
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Summarizing Long Conversations for Handoff
|
|
347
|
+
|
|
348
|
+
A conversation has been going for 30 messages and needs to be handed to a human agent:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
const summary = await zai.summarize(conversationHistory, {
|
|
352
|
+
prompt: "focus on the customer's problem, what has been tried, and current status",
|
|
353
|
+
length: 200,
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Grouping Feedback for Product Review
|
|
358
|
+
|
|
359
|
+
Hundreds of user feedback messages need to be organized into themes:
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
const themes = await zai.group(feedbackMessages, {
|
|
363
|
+
instructions: "group by product area and sentiment",
|
|
364
|
+
});
|
|
365
|
+
// → [{ id: 'onboarding', label: 'Onboarding Issues', elements: [...] }, ...]
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Edge Cases & Gotchas
|
|
369
|
+
|
|
370
|
+
### Ambiguous Input
|
|
371
|
+
|
|
372
|
+
When `check()` gives inconsistent results on borderline inputs, add examples to guide it:
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
await zai.check(text, "is a complaint", {
|
|
376
|
+
examples: [
|
|
377
|
+
{ input: "This is taking too long", check: true, reason: "Expresses frustration with wait time" },
|
|
378
|
+
{ input: "How long does shipping take?", check: false, reason: "Neutral question, not a complaint" },
|
|
379
|
+
],
|
|
380
|
+
});
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### Very Large Documents
|
|
384
|
+
|
|
385
|
+
Zai auto-chunks, but default `chunkLength` (16000 tokens) may lose context across chunks. For documents where cross-chunk context matters (e.g., a contract where definitions appear at the top):
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
await zai.extract(contract, schema, {
|
|
389
|
+
chunkLength: 32000, // Larger chunks to keep definitions in context
|
|
390
|
+
instructions: "Definitions from the 'Definitions' section apply throughout",
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### extract() Returns Hallucinated Fields
|
|
395
|
+
|
|
396
|
+
When the input doesn't contain the requested data, the LLM may invent values. Use `.describe()` on schema fields and strict mode:
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
const data = await zai.extract(text, z.object({
|
|
400
|
+
revenue: z.number().describe("Annual revenue in USD. Use -1 if not mentioned."),
|
|
401
|
+
founded: z.number().describe("Year founded. Use 0 if not mentioned."),
|
|
402
|
+
}), { strict: true });
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### answer() Returns "missing_knowledge" Despite Relevant Docs
|
|
406
|
+
|
|
407
|
+
This usually means the docs are too long and the relevant passage fell outside the chunk window, or the question phrasing doesn't match the document language. Reduce chunk size and add instructions:
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
await zai.answer(docs, question, {
|
|
411
|
+
chunkLength: 4000,
|
|
412
|
+
instructions: "The documents use technical terminology. Match concepts, not exact wording.",
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Mixed-Language Content
|
|
417
|
+
|
|
418
|
+
Zai handles multilingual input natively — no special config needed. But be explicit when you want output in a specific language:
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
await zai.extract(mixedLanguageText, schema, {
|
|
422
|
+
instructions: "Input may be in any language. Always return field values in English.",
|
|
423
|
+
});
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Empty or Minimal Input
|
|
427
|
+
|
|
428
|
+
Zai doesn't error on empty strings but results will be empty/default. Guard at the call site:
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
if (input.trim().length > 0) {
|
|
432
|
+
const result = await zai.extract(input, schema);
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Rate Limiting Under Load
|
|
437
|
+
|
|
438
|
+
When processing batches, stagger requests to avoid hitting API limits:
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
const results = [];
|
|
442
|
+
for (const [i, item] of items.entries()) {
|
|
443
|
+
if (i > 0) await new Promise((r) => setTimeout(r, 200));
|
|
444
|
+
results.push(await zai.extract(item, schema));
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Notes
|
|
449
|
+
|
|
450
|
+
- All operations handle any input size via automatic chunking
|
|
451
|
+
- `.learn()` creates persistent cache - use unique taskIds
|
|
452
|
+
- Exact input matches skip LLM entirely when using `.learn()`
|
|
453
|
+
- All methods are async - use `await`
|
|
454
|
+
- For the full developer guide including architecture, storage, and performance tuning, see [zai-complete-guide.md](./zai-complete-guide.md)
|