@botpress/adk 1.19.0-beta.9 → 2.0.0-alpha.0
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/dist/agent-init/agent-project-generator.d.ts +5 -1
- package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent-project/agent-project.d.ts +3 -3
- package/dist/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/agent-resolver.d.ts.map +1 -1
- package/dist/agent-project/config-writer.d.ts +1 -1
- package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
- package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
- package/dist/agent-project/types.d.ts +9 -4
- package/dist/agent-project/types.d.ts.map +1 -1
- package/dist/agent0/capabilities/commands/adk-build.md +6 -5
- package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
- package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
- package/dist/agent0/capabilities/commands/adk-document.md +10 -2
- package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
- package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
- package/dist/agent0/capabilities/commands/adk-init.md +2 -2
- package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
- package/dist/agent0/capabilities/commands/adk-test.md +3 -3
- package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
- package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
- package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
- package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
- package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
- package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
- package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
- package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
- package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
- package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
- package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
- package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
- package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
- package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
- package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
- package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
- package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
- package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
- package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
- package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
- package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
- package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
- package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
- package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
- package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
- package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
- package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
- package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
- package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
- package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
- package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
- package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
- package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
- package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
- package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
- package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
- package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
- package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
- package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
- package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
- package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
- package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
- package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
- package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
- package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
- package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
- package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
- package/dist/agent0/index.js +41 -19
- package/dist/agent0/index.js.map +7 -7
- package/dist/agent0/runtime/client.d.ts +2 -0
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +2 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +1 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -1
- package/dist/assets/manager.d.ts +3 -0
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/auth/credentials.d.ts +1 -1
- package/dist/bot-generator/generator.d.ts +22 -0
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/commands/base-command.d.ts +1 -0
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-command.d.ts +1 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +9 -0
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
- package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
- package/dist/dependencies/catalog/client-factory.d.ts +33 -0
- package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
- package/dist/dependencies/catalog/integration-source.d.ts +34 -0
- package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/interface-source.d.ts +23 -0
- package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
- package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
- package/dist/dependencies/dependency-manager.d.ts +31 -16
- package/dist/dependencies/dependency-manager.d.ts.map +1 -1
- package/dist/dependencies/errors.d.ts +2 -2
- package/dist/dependencies/errors.d.ts.map +1 -1
- package/dist/dependencies/index.d.ts +5 -4
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +2089 -1670
- package/dist/dependencies/index.js.map +37 -30
- package/dist/dependencies/legacy-lock-file.d.ts +15 -0
- package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
- package/dist/dependencies/migration.d.ts +19 -0
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
- package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
- package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
- package/dist/dependencies/snapshot-store.d.ts +59 -0
- package/dist/dependencies/snapshot-store.d.ts.map +1 -0
- package/dist/dependencies/status-resolver.d.ts +36 -0
- package/dist/dependencies/status-resolver.d.ts.map +1 -0
- package/dist/dependencies/status.d.ts +214 -0
- package/dist/dependencies/status.d.ts.map +1 -0
- package/dist/dependencies/types.d.ts +380 -29
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/file-watcher/watcher.d.ts +21 -5
- package/dist/file-watcher/watcher.d.ts.map +1 -1
- package/dist/generators/action-types.d.ts.map +1 -1
- package/dist/generators/client-wrapper.d.ts.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3134 -2226
- package/dist/index.js.map +55 -48
- package/dist/integrations/config-utils.d.ts +11 -7
- package/dist/integrations/config-utils.d.ts.map +1 -1
- package/dist/integrations/hub-cache.d.ts +0 -58
- package/dist/integrations/hub-cache.d.ts.map +1 -1
- package/dist/integrations/index.d.ts +1 -3
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts +19 -53
- package/dist/integrations/manager.d.ts.map +1 -1
- package/dist/interfaces/enhanced-cache.d.ts +7 -7
- package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
- package/dist/interfaces/manager.d.ts +11 -17
- package/dist/interfaces/manager.d.ts.map +1 -1
- package/dist/knowledge/manager.d.ts +3 -0
- package/dist/knowledge/manager.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts +16 -48
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts +6 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/preflight/dependency-gate.d.ts +37 -0
- package/dist/preflight/dependency-gate.d.ts.map +1 -0
- package/dist/preflight/index.d.ts +2 -1
- package/dist/preflight/index.d.ts.map +1 -1
- package/dist/preflight/types.d.ts +18 -0
- package/dist/preflight/types.d.ts.map +1 -1
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/tables/table-manager.d.ts +3 -0
- package/dist/tables/table-manager.d.ts.map +1 -1
- package/dist/templates/README.md +23 -13
- package/dist/templates/blank/agent.config.ts +3 -3
- package/dist/templates/blank/src/triggers/index.ts +1 -1
- package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
- package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
- package/dist/templates/crm-enrichment/README.md +3 -3
- package/dist/templates/crm-enrichment/agent.config.ts +2 -2
- package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
- package/dist/templates/hello-world/agent.config.ts +3 -3
- package/dist/templates/hello-world/src/triggers/index.ts +1 -1
- package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
- package/dist/templates/template.config.json +3 -3
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -1
- package/dist/workspace/workspace-cache.d.ts +2 -1
- package/dist/workspace/workspace-cache.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
- package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
- package/dist/dependencies/lock-file.d.ts +0 -15
- package/dist/dependencies/lock-file.d.ts.map +0 -1
- package/dist/integrations/enhanced-cache.d.ts +0 -53
- package/dist/integrations/enhanced-cache.d.ts.map +0 -1
- package/dist/plugins/enhanced-cache.d.ts +0 -53
- package/dist/plugins/enhanced-cache.d.ts.map +0 -1
- package/dist/templates/blank/package.json +0 -17
- package/dist/templates/blank/tsconfig.json +0 -25
- package/dist/templates/botpress-desk/package.json +0 -17
- package/dist/templates/crm-enrichment/package.json +0 -18
- package/dist/templates/crm-enrichment/tsconfig.json +0 -25
- package/dist/templates/hello-world/package.json +0 -18
- package/dist/templates/hello-world/tsconfig.json +0 -25
- package/dist/templates/knowledge-assistant/package.json +0 -18
- package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
- package/dist/templates/slack-triage/package.json +0 -18
- package/dist/templates/slack-triage/tsconfig.json +0 -25
|
@@ -7,16 +7,16 @@ Quick reference for configuring AI models at different levels in ADK agents.
|
|
|
7
7
|
## 1. Global Defaults (agent.config.ts)
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
import { defineConfig } from
|
|
10
|
+
import { defineConfig } from '@botpress/runtime'
|
|
11
11
|
|
|
12
12
|
export default defineConfig({
|
|
13
|
-
name:
|
|
13
|
+
name: 'my-agent',
|
|
14
14
|
|
|
15
15
|
defaultModels: {
|
|
16
|
-
autonomous:
|
|
17
|
-
zai:
|
|
18
|
-
}
|
|
19
|
-
})
|
|
16
|
+
autonomous: 'openai:gpt-4o', // Used by execute()
|
|
17
|
+
zai: 'openai:gpt-4o-mini', // Used by Zai operations
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
### With Fallback Arrays
|
|
@@ -38,22 +38,19 @@ defaultModels: {
|
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
40
|
await execute({
|
|
41
|
-
instructions:
|
|
42
|
-
model:
|
|
43
|
-
temperature: 0.7
|
|
44
|
-
})
|
|
41
|
+
instructions: 'You are a helpful assistant',
|
|
42
|
+
model: 'anthropic:claude-3-5-sonnet',
|
|
43
|
+
temperature: 0.7,
|
|
44
|
+
})
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
### With Fallback Array
|
|
48
48
|
|
|
49
49
|
```typescript
|
|
50
50
|
await execute({
|
|
51
|
-
instructions:
|
|
52
|
-
model: [
|
|
53
|
-
|
|
54
|
-
"anthropic:claude-3-5-sonnet"
|
|
55
|
-
]
|
|
56
|
-
});
|
|
51
|
+
instructions: 'You are a helpful assistant',
|
|
52
|
+
model: ['openai:gpt-4o', 'anthropic:claude-3-5-sonnet'],
|
|
53
|
+
})
|
|
57
54
|
```
|
|
58
55
|
|
|
59
56
|
---
|
|
@@ -63,10 +60,10 @@ await execute({
|
|
|
63
60
|
Override the default Zai model per-instance using `.with()`:
|
|
64
61
|
|
|
65
62
|
```typescript
|
|
66
|
-
import { adk } from
|
|
63
|
+
import { adk } from '@botpress/runtime'
|
|
67
64
|
|
|
68
|
-
const preciseZai = adk.zai.with({ modelId:
|
|
69
|
-
await preciseZai.extract(text, schema)
|
|
65
|
+
const preciseZai = adk.zai.with({ modelId: 'openai:gpt-4o' })
|
|
66
|
+
await preciseZai.extract(text, schema)
|
|
70
67
|
```
|
|
71
68
|
|
|
72
69
|
> For full Zai configuration (initialization, chaining, learning, operations), see [zai-agent-reference.md](./zai-agent-reference.md) and [zai-complete-guide.md](./zai-complete-guide.md).
|
|
@@ -80,15 +77,16 @@ await preciseZai.extract(text, schema);
|
|
|
80
77
|
Models follow the pattern: `{provider}:{model-name}`
|
|
81
78
|
|
|
82
79
|
```typescript
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
'openai:gpt-4o' // Short name
|
|
81
|
+
'openai:gpt-4.1-2025-04-14' // Dated version (more specific)
|
|
82
|
+
'anthropic:claude-3-5-sonnet' // Short name
|
|
83
|
+
'anthropic:claude-sonnet-4-5-20250929' // Dated version
|
|
84
|
+
'best' // Zai shortcut (highest quality)
|
|
85
|
+
'fast' // Zai shortcut (fastest/cheapest)
|
|
89
86
|
```
|
|
90
87
|
|
|
91
88
|
**Finding Available Models:**
|
|
89
|
+
|
|
92
90
|
- The Models type accepts any string, so new models work automatically
|
|
93
91
|
- For current available models, check the `Models` type in `@botpress/cognitive`
|
|
94
92
|
- Use TypeScript autocomplete: Start typing a provider name to see suggestions
|
|
@@ -97,6 +95,7 @@ Models follow the pattern: `{provider}:{model-name}`
|
|
|
97
95
|
### Common Models
|
|
98
96
|
|
|
99
97
|
### OpenAI
|
|
98
|
+
|
|
100
99
|
```
|
|
101
100
|
openai:gpt-4o
|
|
102
101
|
openai:gpt-4o-mini
|
|
@@ -105,6 +104,7 @@ openai:gpt-3.5-turbo
|
|
|
105
104
|
```
|
|
106
105
|
|
|
107
106
|
### Anthropic
|
|
107
|
+
|
|
108
108
|
```
|
|
109
109
|
anthropic:claude-3-5-sonnet
|
|
110
110
|
anthropic:claude-3-opus
|
|
@@ -112,17 +112,20 @@ anthropic:claude-3-haiku
|
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
### Google
|
|
115
|
+
|
|
115
116
|
```
|
|
116
117
|
google:gemini-1.5-pro
|
|
117
118
|
google:gemini-1.5-flash
|
|
118
119
|
```
|
|
119
120
|
|
|
120
121
|
### Cerebras
|
|
122
|
+
|
|
121
123
|
```
|
|
122
124
|
cerebras:gpt-oss-120b
|
|
123
125
|
```
|
|
124
126
|
|
|
125
127
|
### Zai Shortcuts
|
|
128
|
+
|
|
126
129
|
```
|
|
127
130
|
best # Highest quality model
|
|
128
131
|
fast # Fastest/cheapest model
|
|
@@ -133,10 +136,12 @@ fast # Fastest/cheapest model
|
|
|
133
136
|
## 5. Precedence Order
|
|
134
137
|
|
|
135
138
|
**For execute():**
|
|
139
|
+
|
|
136
140
|
1. `execute({ model: "..." })` - Per-call override
|
|
137
141
|
2. `agent.config.ts defaultModels.autonomous` - Global default
|
|
138
142
|
|
|
139
143
|
**For Zai:**
|
|
144
|
+
|
|
140
145
|
1. `zai.with({ modelId: "..." })` - Instance override
|
|
141
146
|
2. `new Zai({ modelId: "..." })` - Constructor config
|
|
142
147
|
3. `agent.config.ts defaultModels.zai` - Global default
|
|
@@ -147,12 +152,12 @@ fast # Fastest/cheapest model
|
|
|
147
152
|
|
|
148
153
|
```typescript
|
|
149
154
|
export default defineConfig({
|
|
150
|
-
name:
|
|
155
|
+
name: 'my-agent',
|
|
151
156
|
defaultModels: {
|
|
152
|
-
autonomous: process.env.AI_MODEL ||
|
|
153
|
-
zai: process.env.ZAI_MODEL ||
|
|
154
|
-
}
|
|
155
|
-
})
|
|
157
|
+
autonomous: process.env.AI_MODEL || 'openai:gpt-4o',
|
|
158
|
+
zai: process.env.ZAI_MODEL || 'openai:gpt-4o-mini',
|
|
159
|
+
},
|
|
160
|
+
})
|
|
156
161
|
```
|
|
157
162
|
|
|
158
163
|
---
|
|
@@ -163,39 +168,37 @@ export default defineConfig({
|
|
|
163
168
|
|
|
164
169
|
```typescript
|
|
165
170
|
export default new Conversation({
|
|
166
|
-
channel:
|
|
171
|
+
channel: '*',
|
|
167
172
|
handler: async ({ execute }) => {
|
|
168
173
|
await execute({
|
|
169
|
-
instructions:
|
|
170
|
-
model:
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
+
instructions: 'You are a helpful assistant',
|
|
175
|
+
model: 'anthropic:claude-3-5-sonnet',
|
|
176
|
+
})
|
|
177
|
+
},
|
|
178
|
+
})
|
|
174
179
|
```
|
|
175
180
|
|
|
176
181
|
### Workflow with Model Override
|
|
177
182
|
|
|
178
183
|
```typescript
|
|
179
184
|
export default Workflow({
|
|
180
|
-
name:
|
|
185
|
+
name: 'research',
|
|
181
186
|
handler: async ({ step, execute }) => {
|
|
182
|
-
const result = await step(
|
|
187
|
+
const result = await step('analyze', async () => {
|
|
183
188
|
return await execute({
|
|
184
|
-
instructions:
|
|
185
|
-
model:
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
return result
|
|
189
|
-
}
|
|
190
|
-
})
|
|
189
|
+
instructions: 'Analyze this data',
|
|
190
|
+
model: 'openai:gpt-4o',
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
return result
|
|
194
|
+
},
|
|
195
|
+
})
|
|
191
196
|
```
|
|
192
197
|
|
|
193
198
|
### Zai Operation with Specific Model
|
|
194
199
|
|
|
195
200
|
```typescript
|
|
196
|
-
import { adk } from
|
|
201
|
+
import { adk } from '@botpress/runtime'
|
|
197
202
|
|
|
198
|
-
const analysis = await adk.zai
|
|
199
|
-
.with({ modelId: "anthropic:claude-3-5-sonnet" })
|
|
200
|
-
.extract(document, schema);
|
|
203
|
+
const analysis = await adk.zai.with({ modelId: 'anthropic:claude-3-5-sonnet' }).extract(document, schema)
|
|
201
204
|
```
|
|
@@ -10,15 +10,16 @@ Common patterns to follow and mistakes to avoid when building with the ADK.
|
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
// ❌ WRONG - Never import from these
|
|
13
|
-
import { z } from
|
|
14
|
-
import { Action } from
|
|
15
|
-
import { Workflow } from
|
|
13
|
+
import { z } from 'zod'
|
|
14
|
+
import { Action } from '@botpress/sdk'
|
|
15
|
+
import { Workflow } from '@botpress/cli'
|
|
16
16
|
|
|
17
17
|
// ✅ CORRECT - Always import from @botpress/runtime
|
|
18
|
-
import { z, Action, Workflow, Conversation } from
|
|
18
|
+
import { z, Action, Workflow, Conversation } from '@botpress/runtime'
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
**Why this matters:**
|
|
22
|
+
|
|
22
23
|
- `z` from `@botpress/runtime` is Botpress's internal fork of Zod (based on Zod 3.x)
|
|
23
24
|
- Importing from `zod` directly can cause compatibility issues
|
|
24
25
|
- ADK primitives (Action, Tool, Workflow, etc.) must come from `@botpress/runtime`
|
|
@@ -30,10 +31,10 @@ Botpress uses Zod 3.x internally. If adding `zod` to your project dependencies (
|
|
|
30
31
|
|
|
31
32
|
```typescript
|
|
32
33
|
// ❌ AVOID - Dynamic imports can cause issues
|
|
33
|
-
const { myAction } = await import(
|
|
34
|
+
const { myAction } = await import('./actions/myAction')
|
|
34
35
|
|
|
35
36
|
// ✅ PREFER - Static imports
|
|
36
|
-
import { myAction } from
|
|
37
|
+
import { myAction } from './actions/myAction'
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
### Handler Syntax
|
|
@@ -46,16 +47,16 @@ Action handlers receive a props object with `input` and `client`. Both arrow fun
|
|
|
46
47
|
// ✅ CORRECT - Method syntax
|
|
47
48
|
export const myAction = new Action({
|
|
48
49
|
async handler({ input }) {
|
|
49
|
-
return { data: input.userId }
|
|
50
|
+
return { data: input.userId }
|
|
50
51
|
},
|
|
51
|
-
})
|
|
52
|
+
})
|
|
52
53
|
|
|
53
54
|
// ✅ ALSO CORRECT - Arrow function syntax
|
|
54
55
|
export const myAction = new Action({
|
|
55
56
|
handler: async ({ input }) => {
|
|
56
|
-
return { data: input.userId }
|
|
57
|
+
return { data: input.userId }
|
|
57
58
|
},
|
|
58
|
-
})
|
|
59
|
+
})
|
|
59
60
|
```
|
|
60
61
|
|
|
61
62
|
#### Tool Handlers
|
|
@@ -64,9 +65,9 @@ export const myAction = new Action({
|
|
|
64
65
|
// ✅ Tools use arrow functions
|
|
65
66
|
export const myTool = new Autonomous.Tool({
|
|
66
67
|
handler: async ({ query, limit }) => {
|
|
67
|
-
return searchResults
|
|
68
|
+
return searchResults
|
|
68
69
|
},
|
|
69
|
-
})
|
|
70
|
+
})
|
|
70
71
|
```
|
|
71
72
|
|
|
72
73
|
### State Management Mistakes
|
|
@@ -80,17 +81,17 @@ Conversations receive `state` as a destructured handler parameter. Do **not** us
|
|
|
80
81
|
export const Chat = new Conversation({
|
|
81
82
|
state: z.object({ count: z.number().default(0) }),
|
|
82
83
|
async handler({ message }) {
|
|
83
|
-
this.state.count += 1
|
|
84
|
+
this.state.count += 1 // ❌ Wrong!
|
|
84
85
|
},
|
|
85
|
-
})
|
|
86
|
+
})
|
|
86
87
|
|
|
87
88
|
// ✅ CORRECT - Use the state parameter
|
|
88
89
|
export const Chat = new Conversation({
|
|
89
90
|
state: z.object({ count: z.number().default(0) }),
|
|
90
91
|
handler: async ({ message, state }) => {
|
|
91
|
-
state.count += 1
|
|
92
|
+
state.count += 1 // ✅ Destructured from handler props
|
|
92
93
|
},
|
|
93
|
-
})
|
|
94
|
+
})
|
|
94
95
|
```
|
|
95
96
|
|
|
96
97
|
#### State Reference vs Value
|
|
@@ -98,31 +99,32 @@ export const Chat = new Conversation({
|
|
|
98
99
|
```typescript
|
|
99
100
|
// ❌ WRONG - Passing state reference to async function
|
|
100
101
|
handler: async ({ step, state }) => {
|
|
101
|
-
const results = await processItems(state.items)
|
|
102
|
+
const results = await processItems(state.items)
|
|
102
103
|
// state.items may have changed while processItems was running
|
|
103
|
-
state.items.push(
|
|
104
|
+
state.items.push('new-item') // processItems might see this!
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
// ✅ CORRECT - Pass a copy of the value
|
|
107
108
|
handler: async ({ step, state }) => {
|
|
108
|
-
const itemsCopy = [...state.items]
|
|
109
|
-
const results = await processItems(itemsCopy)
|
|
110
|
-
state.items.push(
|
|
109
|
+
const itemsCopy = [...state.items]
|
|
110
|
+
const results = await processItems(itemsCopy)
|
|
111
|
+
state.items.push('new-item') // safe, doesn't affect processItems
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
// ✅ CORRECT - Extract values before async operation
|
|
114
115
|
handler: async ({ step, state }) => {
|
|
115
|
-
const currentCount = state.count
|
|
116
|
-
const currentItems = [...state.items]
|
|
117
|
-
const currentConfig = { ...state.config }
|
|
116
|
+
const currentCount = state.count // Primitive - safe
|
|
117
|
+
const currentItems = [...state.items] // Array - needs spread
|
|
118
|
+
const currentConfig = { ...state.config } // Object - needs spread
|
|
118
119
|
|
|
119
|
-
await step(
|
|
120
|
-
return await processData(currentCount, currentItems, currentConfig)
|
|
121
|
-
})
|
|
120
|
+
await step('process', async () => {
|
|
121
|
+
return await processData(currentCount, currentItems, currentConfig)
|
|
122
|
+
})
|
|
122
123
|
}
|
|
123
124
|
```
|
|
124
125
|
|
|
125
126
|
**Rules of thumb:**
|
|
127
|
+
|
|
126
128
|
- **Primitives** (string, number, boolean): Can pass directly
|
|
127
129
|
- **Arrays**: Use spread `[...state.items]` or `Array.from()`
|
|
128
130
|
- **Objects**: Use spread `{ ...state.config }` or `structuredClone()`
|
|
@@ -136,35 +138,35 @@ handler: async ({ step, state }) => {
|
|
|
136
138
|
// ❌ WRONG - Dynamic step names break resume
|
|
137
139
|
for (let i = 0; i < items.length; i++) {
|
|
138
140
|
await step(`process-${i}`, async () => {
|
|
139
|
-
await processItem(items[i])
|
|
140
|
-
})
|
|
141
|
+
await processItem(items[i])
|
|
142
|
+
})
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
// ✅ CORRECT - Single step with loop
|
|
144
|
-
await step(
|
|
146
|
+
await step('process-all', async () => {
|
|
145
147
|
for (const item of items) {
|
|
146
|
-
await processItem(item)
|
|
148
|
+
await processItem(item)
|
|
147
149
|
}
|
|
148
|
-
})
|
|
150
|
+
})
|
|
149
151
|
|
|
150
152
|
// ✅ CORRECT - Or use step.map
|
|
151
|
-
await step.map(
|
|
152
|
-
return processItem(item)
|
|
153
|
-
})
|
|
153
|
+
await step.map('process-items', items, async (item) => {
|
|
154
|
+
return processItem(item)
|
|
155
|
+
})
|
|
154
156
|
```
|
|
155
157
|
|
|
156
158
|
#### Missing Await on Steps
|
|
157
159
|
|
|
158
160
|
```typescript
|
|
159
161
|
// ❌ WRONG - Missing await
|
|
160
|
-
const result = step(
|
|
161
|
-
return fetchData()
|
|
162
|
-
})
|
|
162
|
+
const result = step('fetch', async () => {
|
|
163
|
+
return fetchData()
|
|
164
|
+
})
|
|
163
165
|
|
|
164
166
|
// ✅ CORRECT - Always await steps
|
|
165
|
-
const result = await step(
|
|
166
|
-
return fetchData()
|
|
167
|
-
})
|
|
167
|
+
const result = await step('fetch', async () => {
|
|
168
|
+
return fetchData()
|
|
169
|
+
})
|
|
168
170
|
```
|
|
169
171
|
|
|
170
172
|
### Table Column Mistakes
|
|
@@ -192,15 +194,15 @@ columns: {
|
|
|
192
194
|
// ❌ WRONG - Missing conversationId prevents communication
|
|
193
195
|
await MyWorkflow.start({
|
|
194
196
|
userId: user.id,
|
|
195
|
-
data:
|
|
196
|
-
})
|
|
197
|
+
data: 'some data',
|
|
198
|
+
})
|
|
197
199
|
|
|
198
200
|
// ✅ CORRECT - Include conversationId for messaging
|
|
199
201
|
await MyWorkflow.start({
|
|
200
202
|
conversationId: conversation.id,
|
|
201
203
|
userId: user.id,
|
|
202
|
-
data:
|
|
203
|
-
})
|
|
204
|
+
data: 'some data',
|
|
205
|
+
})
|
|
204
206
|
```
|
|
205
207
|
|
|
206
208
|
---
|
|
@@ -213,18 +215,15 @@ Request data from user during workflow execution:
|
|
|
213
215
|
|
|
214
216
|
```typescript
|
|
215
217
|
export const MyWorkflow = new Workflow({
|
|
216
|
-
name:
|
|
218
|
+
name: 'interactive',
|
|
217
219
|
requests: {
|
|
218
220
|
topic: z.object({ topic: z.string() }),
|
|
219
221
|
},
|
|
220
222
|
handler: async ({ step, input }) => {
|
|
221
|
-
const { topic } = await step.request(
|
|
222
|
-
|
|
223
|
-
"What is the topic of the question?"
|
|
224
|
-
);
|
|
225
|
-
console.log(`Topic identified: ${topic}`);
|
|
223
|
+
const { topic } = await step.request('topic', 'What is the topic of the question?')
|
|
224
|
+
console.log(`Topic identified: ${topic}`)
|
|
226
225
|
},
|
|
227
|
-
})
|
|
226
|
+
})
|
|
228
227
|
```
|
|
229
228
|
|
|
230
229
|
### RAG with Citations
|
|
@@ -232,38 +231,38 @@ export const MyWorkflow = new Workflow({
|
|
|
232
231
|
Use citations to track sources for AI-generated responses:
|
|
233
232
|
|
|
234
233
|
```typescript
|
|
235
|
-
import { Autonomous, context } from
|
|
234
|
+
import { Autonomous, context } from '@botpress/runtime'
|
|
236
235
|
|
|
237
236
|
const SearchTool = new Autonomous.Tool({
|
|
238
|
-
name:
|
|
237
|
+
name: 'search',
|
|
239
238
|
input: z.string(),
|
|
240
239
|
output: z.string(),
|
|
241
240
|
handler: async (query) => {
|
|
242
|
-
const client = context.get(
|
|
243
|
-
const citations = context.get(
|
|
241
|
+
const client = context.get('client')
|
|
242
|
+
const citations = context.get('citations')
|
|
244
243
|
|
|
245
244
|
const { passages } = await client.searchFiles({
|
|
246
245
|
query,
|
|
247
|
-
tags: { type:
|
|
248
|
-
})
|
|
246
|
+
tags: { type: 'knowledge', kb: ['myKB'] },
|
|
247
|
+
})
|
|
249
248
|
|
|
250
|
-
const message = [
|
|
251
|
-
const { tag: example } = citations.registerSource({})
|
|
249
|
+
const message = ['Here are the search results:']
|
|
250
|
+
const { tag: example } = citations.registerSource({})
|
|
252
251
|
|
|
253
252
|
for (const p of passages) {
|
|
254
|
-
const { tag } = citations.registerSource({ file: p.file.key })
|
|
255
|
-
message.push(`<${tag} file="${p.file.key}">`)
|
|
256
|
-
message.push(`**${p.file.tags.title}**`)
|
|
257
|
-
message.push(p.content)
|
|
258
|
-
message.push(`</${tag}>`)
|
|
253
|
+
const { tag } = citations.registerSource({ file: p.file.key })
|
|
254
|
+
message.push(`<${tag} file="${p.file.key}">`)
|
|
255
|
+
message.push(`**${p.file.tags.title}**`)
|
|
256
|
+
message.push(p.content)
|
|
257
|
+
message.push(`</${tag}>`)
|
|
259
258
|
}
|
|
260
259
|
|
|
261
260
|
throw new Autonomous.ThinkSignal(
|
|
262
261
|
`When answering, MUST add inline citations (eg: "The price is $10${example} ...")`,
|
|
263
|
-
message.join(
|
|
264
|
-
)
|
|
262
|
+
message.join('\n')
|
|
263
|
+
)
|
|
265
264
|
},
|
|
266
|
-
})
|
|
265
|
+
})
|
|
267
266
|
```
|
|
268
267
|
|
|
269
268
|
### Context Access Patterns
|
|
@@ -273,19 +272,19 @@ The context API provides access to runtime services within handlers.
|
|
|
273
272
|
#### Basic Context Usage
|
|
274
273
|
|
|
275
274
|
```typescript
|
|
276
|
-
import { context } from
|
|
275
|
+
import { context } from '@botpress/runtime'
|
|
277
276
|
|
|
278
277
|
export const myAction = new Action({
|
|
279
278
|
handler: async ({ input }) => {
|
|
280
|
-
const client = context.get(
|
|
281
|
-
const cognitive = context.get(
|
|
282
|
-
const logger = context.get(
|
|
279
|
+
const client = context.get('client')
|
|
280
|
+
const cognitive = context.get('cognitive')
|
|
281
|
+
const logger = context.get('logger')
|
|
283
282
|
|
|
284
|
-
const { passages } = await client.searchFiles({ query: input.query })
|
|
285
|
-
logger.info(
|
|
286
|
-
return { results: passages }
|
|
283
|
+
const { passages } = await client.searchFiles({ query: input.query })
|
|
284
|
+
logger.info('Search completed', { resultCount: passages.length })
|
|
285
|
+
return { results: passages }
|
|
287
286
|
},
|
|
288
|
-
})
|
|
287
|
+
})
|
|
289
288
|
```
|
|
290
289
|
|
|
291
290
|
#### Optional Context Keys
|
|
@@ -293,21 +292,22 @@ export const myAction = new Action({
|
|
|
293
292
|
```typescript
|
|
294
293
|
export const myAction = new Action({
|
|
295
294
|
handler: async ({ input }) => {
|
|
296
|
-
const user = context.get(
|
|
297
|
-
const conversation = context.get(
|
|
295
|
+
const user = context.get('user', { optional: true })
|
|
296
|
+
const conversation = context.get('conversation', { optional: true })
|
|
298
297
|
|
|
299
298
|
if (user && conversation) {
|
|
300
|
-
console.log(`User ${user.id} in conversation ${conversation.id}`)
|
|
299
|
+
console.log(`User ${user.id} in conversation ${conversation.id}`)
|
|
301
300
|
} else {
|
|
302
|
-
console.log(
|
|
301
|
+
console.log('Processing without user context')
|
|
303
302
|
}
|
|
304
303
|
},
|
|
305
|
-
})
|
|
304
|
+
})
|
|
306
305
|
```
|
|
307
306
|
|
|
308
307
|
#### Common Context Keys
|
|
309
308
|
|
|
310
309
|
**Always Available:**
|
|
310
|
+
|
|
311
311
|
- `client` — Botpress API client
|
|
312
312
|
- `cognitive` — AI model client
|
|
313
313
|
- `logger` — Structured logger
|
|
@@ -316,6 +316,7 @@ export const myAction = new Action({
|
|
|
316
316
|
- `runtime` — Runtime environment info
|
|
317
317
|
|
|
318
318
|
**Conditionally Available:**
|
|
319
|
+
|
|
319
320
|
- `user` — Current user (in conversation handlers)
|
|
320
321
|
- `conversation` — Current conversation (in conversation handlers, not to be used within a conversation object: use the `conversation` parameter instead)
|
|
321
322
|
- `message` — Incoming message (when triggered by message)
|
|
@@ -325,13 +326,13 @@ export const myAction = new Action({
|
|
|
325
326
|
|
|
326
327
|
#### Context in Different Handler Types
|
|
327
328
|
|
|
328
|
-
| Handler
|
|
329
|
-
|
|
330
|
-
| **Actions**
|
|
331
|
-
| **Tools**
|
|
332
|
-
| **Workflows**
|
|
333
|
-
| **Conversations** | `client`, `user`, `conversation`, `message`, `event`?, `logger`
|
|
334
|
-
| **Triggers**
|
|
329
|
+
| Handler | Key context keys |
|
|
330
|
+
| ----------------- | ---------------------------------------------------------------------- |
|
|
331
|
+
| **Actions** | `client`, `cognitive`, `logger`, `botId`, `configuration` |
|
|
332
|
+
| **Tools** | `client`, `cognitive`, `citations`, `logger`, `user`?, `conversation`? |
|
|
333
|
+
| **Workflows** | `client`, `workflow`, `workflowControlContext`, `logger` |
|
|
334
|
+
| **Conversations** | `client`, `user`, `conversation`, `message`, `event`?, `logger` |
|
|
335
|
+
| **Triggers** | `client`, `event`, `logger` |
|
|
335
336
|
|
|
336
337
|
---
|
|
337
338
|
|
|
@@ -372,19 +373,19 @@ src/knowledge/policies/privacy.md
|
|
|
372
373
|
|
|
373
374
|
```typescript
|
|
374
375
|
// Actions
|
|
375
|
-
export const fetchUser = new Action({ name:
|
|
376
|
+
export const fetchUser = new Action({ name: 'fetchUser' })
|
|
376
377
|
|
|
377
378
|
// Workflows
|
|
378
|
-
export const OnboardingWorkflow = new Workflow({ name:
|
|
379
|
+
export const OnboardingWorkflow = new Workflow({ name: 'onboarding' })
|
|
379
380
|
|
|
380
381
|
// Tables
|
|
381
|
-
export const UsersTable = new Table({ name:
|
|
382
|
+
export const UsersTable = new Table({ name: 'users' })
|
|
382
383
|
|
|
383
384
|
// Conversations
|
|
384
|
-
export const Chat = new Conversation({ channel:
|
|
385
|
+
export const Chat = new Conversation({ channel: 'chat.channel' })
|
|
385
386
|
|
|
386
387
|
// Triggers - use default export
|
|
387
|
-
export default new Trigger({ name:
|
|
388
|
+
export default new Trigger({ name: 'userEvents' })
|
|
388
389
|
```
|
|
389
390
|
|
|
390
391
|
---
|
|
@@ -433,12 +434,12 @@ grep -r "from \"@botpress/sdk\"" src/
|
|
|
433
434
|
```typescript
|
|
434
435
|
// In conversations - use state parameter
|
|
435
436
|
handler: async ({ state }) => {
|
|
436
|
-
console.log(
|
|
437
|
+
console.log('Conversation state:', JSON.stringify(state, null, 2))
|
|
437
438
|
}
|
|
438
439
|
|
|
439
440
|
// In workflows - use state parameter
|
|
440
441
|
handler: async ({ state }) => {
|
|
441
|
-
console.log(
|
|
442
|
+
console.log('Workflow state:', JSON.stringify(state, null, 2))
|
|
442
443
|
}
|
|
443
444
|
```
|
|
444
445
|
|
|
@@ -446,14 +447,14 @@ handler: async ({ state }) => {
|
|
|
446
447
|
|
|
447
448
|
```typescript
|
|
448
449
|
handler: async ({ step }) => {
|
|
449
|
-
console.log(
|
|
450
|
+
console.log('Starting workflow')
|
|
450
451
|
|
|
451
|
-
const result = await step(
|
|
452
|
-
console.log(
|
|
453
|
-
return
|
|
454
|
-
})
|
|
452
|
+
const result = await step('step1', async () => {
|
|
453
|
+
console.log('Executing step1')
|
|
454
|
+
return 'data'
|
|
455
|
+
})
|
|
455
456
|
|
|
456
|
-
console.log(
|
|
457
|
+
console.log('Step1 result:', result)
|
|
457
458
|
}
|
|
458
459
|
```
|
|
459
460
|
|