@andreprado/agentkit 0.1.0-alpha.10

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.
Files changed (122) hide show
  1. package/README.md +69 -0
  2. package/bin/agentkit.mjs +23 -0
  3. package/docs/guides/add-channel.md +114 -0
  4. package/docs/guides/add-knowledge.md +134 -0
  5. package/docs/guides/add-tool.md +342 -0
  6. package/docs/guides/agentkit-skills-architecture.md +471 -0
  7. package/docs/guides/channel-security.md +81 -0
  8. package/docs/guides/channels-implementation-map.md +243 -0
  9. package/docs/guides/channels-production-handoff.md +102 -0
  10. package/docs/guides/connect-telegram.md +110 -0
  11. package/docs/guides/connect-whatsapp-zapster.md +119 -0
  12. package/docs/guides/create-agent.md +220 -0
  13. package/docs/guides/prepare-deploy.md +209 -0
  14. package/docs/guides/run-evals.md +179 -0
  15. package/docs/guides/security-rules.md +156 -0
  16. package/docs/guides/use-provider.md +140 -0
  17. package/docs/llms-full.txt +876 -0
  18. package/docs/llms.txt +83 -0
  19. package/docs/portable-deploy-release-checklist.md +41 -0
  20. package/package.json +47 -0
  21. package/src/cli/args.ts +36 -0
  22. package/src/cli/cloud-client.ts +265 -0
  23. package/src/cli/commands/channels.ts +810 -0
  24. package/src/cli/commands/knowledge.ts +136 -0
  25. package/src/cli/constants.ts +4 -0
  26. package/src/cli/deploy-chat-ui.ts +392 -0
  27. package/src/cli/deploy-readiness.ts +348 -0
  28. package/src/cli/flags.ts +162 -0
  29. package/src/cli/help.ts +184 -0
  30. package/src/cli/index.ts +1276 -0
  31. package/src/cli/process.ts +31 -0
  32. package/src/cloud/artifact.ts +139 -0
  33. package/src/cloud/client.ts +79 -0
  34. package/src/cloud/contracts.ts +63 -0
  35. package/src/cloud/index.ts +3 -0
  36. package/src/create-project.ts +177 -0
  37. package/src/index.ts +408 -0
  38. package/src/providers/index.ts +25 -0
  39. package/src/providers/pi.ts +286 -0
  40. package/src/providers/test.ts +133 -0
  41. package/src/providers/types.ts +34 -0
  42. package/src/runtime/build.ts +43 -0
  43. package/src/runtime/channel-buffer.ts +30 -0
  44. package/src/runtime/channel-test-harness.ts +112 -0
  45. package/src/runtime/channels/telegram.ts +360 -0
  46. package/src/runtime/channels/website.ts +132 -0
  47. package/src/runtime/channels/whatsapp-meta.ts +71 -0
  48. package/src/runtime/channels/whatsapp-zapster.ts +278 -0
  49. package/src/runtime/channels.ts +138 -0
  50. package/src/runtime/chat.ts +218 -0
  51. package/src/runtime/config.ts +684 -0
  52. package/src/runtime/conversations.ts +38 -0
  53. package/src/runtime/core/deploy-state.ts +54 -0
  54. package/src/runtime/core/manifest.ts +213 -0
  55. package/src/runtime/core/targets.ts +133 -0
  56. package/src/runtime/database.ts +256 -0
  57. package/src/runtime/db-commands.ts +167 -0
  58. package/src/runtime/deploy-readiness.ts +105 -0
  59. package/src/runtime/deploy.ts +1 -0
  60. package/src/runtime/dev-server.ts +1247 -0
  61. package/src/runtime/docs.ts +36 -0
  62. package/src/runtime/env.ts +152 -0
  63. package/src/runtime/errors.ts +13 -0
  64. package/src/runtime/evals.ts +509 -0
  65. package/src/runtime/inspect.ts +203 -0
  66. package/src/runtime/knowledge/chunk.ts +333 -0
  67. package/src/runtime/knowledge/config.ts +135 -0
  68. package/src/runtime/knowledge/embeddings.ts +133 -0
  69. package/src/runtime/knowledge/ingest.ts +521 -0
  70. package/src/runtime/knowledge/prompt-policy.ts +30 -0
  71. package/src/runtime/knowledge/retrieve.ts +283 -0
  72. package/src/runtime/knowledge/schema.ts +56 -0
  73. package/src/runtime/knowledge/tool.ts +64 -0
  74. package/src/runtime/knowledge/vector.ts +258 -0
  75. package/src/runtime/runtime-contract.ts +93 -0
  76. package/src/runtime/spec.ts +152 -0
  77. package/src/runtime/sync.ts +144 -0
  78. package/src/runtime/targets/cloudflare/build.ts +2517 -0
  79. package/src/runtime/targets/container/build.ts +146 -0
  80. package/src/runtime/targets/container/server.ts +33 -0
  81. package/src/runtime/targets/vps/deploy.ts +206 -0
  82. package/src/runtime/tool-runner.ts +65 -0
  83. package/src/runtime/tools.ts +470 -0
  84. package/src/runtime/traces.ts +41 -0
  85. package/src/storage/sqlite.ts +1118 -0
  86. package/src/templates/blank.ts +394 -0
  87. package/src/templates/dentista.ts +1003 -0
  88. package/src/templates/index.ts +33 -0
  89. package/src/templates/skills/agentkit-build-agent/SKILL.md +51 -0
  90. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +20 -0
  91. package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
  92. package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
  93. package/src/templates/skills/agentkit-capsule/SKILL.md +62 -0
  94. package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
  95. package/src/templates/skills/agentkit-channels/SKILL.md +62 -0
  96. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +58 -0
  97. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +41 -0
  98. package/src/templates/skills/agentkit-channels/references/telegram.md +38 -0
  99. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +44 -0
  100. package/src/templates/skills/agentkit-database/SKILL.md +45 -0
  101. package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
  102. package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
  103. package/src/templates/skills/agentkit-deploy/SKILL.md +44 -0
  104. package/src/templates/skills/agentkit-evals/SKILL.md +60 -0
  105. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +22 -0
  106. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +14 -0
  107. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +14 -0
  108. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +18 -0
  109. package/src/templates/skills/agentkit-knowledge/SKILL.md +40 -0
  110. package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
  111. package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
  112. package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
  113. package/src/templates/skills/agentkit-prompts/SKILL.md +45 -0
  114. package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
  115. package/src/templates/skills/agentkit-provider/SKILL.md +57 -0
  116. package/src/templates/skills/agentkit-security/SKILL.md +55 -0
  117. package/src/templates/skills/agentkit-tools/SKILL.md +36 -0
  118. package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
  119. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
  120. package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
  121. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +52 -0
  122. package/src/templates/support.ts +401 -0
@@ -0,0 +1,876 @@
1
+ # AgentKit Full Agent Contract
2
+
3
+ Use this file when you are a coding agent creating, editing, testing, or preparing an AgentKit Agent Capsule.
4
+
5
+ ## What AgentKit Is
6
+
7
+ AgentKit is a CLI-first toolkit for Agent Capsules.
8
+
9
+ An Agent Capsule is a folder that contains:
10
+
11
+ ```txt
12
+ agentkit.config.ts
13
+ package.json
14
+ tsconfig.json
15
+ .env.schema
16
+ .gitignore
17
+ AGENTS.md
18
+ AGENTKIT.md
19
+ CLAUDE.md
20
+ README.md
21
+ src/
22
+ prompts/
23
+ tools/
24
+ evals/
25
+ .agentkit/
26
+ ```
27
+
28
+ The capsule root is the runtime boundary. Run AgentKit commands from the directory that contains `agentkit.config.ts`.
29
+ `agentkit new` initializes a Git repository in the generated capsule when `.git` does not already exist.
30
+
31
+ ## Current Command Surface
32
+
33
+ Current commands:
34
+
35
+ ```sh
36
+ agentkit new <name> [--template blank|support|dentista] [--no-install]
37
+ agentkit dev [--port <number>]
38
+ agentkit open
39
+ agentkit chat-ui --deploy
40
+ agentkit chat-ui --deploy [--port <number>] [--token-file <path>]
41
+ agentkit chat --message <text> [--conversation-id <id>]
42
+ agentkit tool <name> [--input <path-or-json>]
43
+ agentkit knowledge add <path-or-url>
44
+ agentkit knowledge sync
45
+ agentkit knowledge inspect
46
+ agentkit knowledge search <query> [--top-k <number>]
47
+ agentkit db migrate
48
+ agentkit db reset --yes
49
+ agentkit db shell
50
+ agentkit db seed [--file <path>]
51
+ agentkit eval run
52
+ agentkit conversations list
53
+ agentkit conversations show <conversation-id>
54
+ agentkit channels list
55
+ agentkit channels add <website|telegram|whatsapp> <name> [--provider zapster|meta] [--api <url>]
56
+ agentkit channels setup <name> [--apply] [--api <url>]
57
+ agentkit channels status <name> [--api <url>]
58
+ agentkit channels test <name> [--message <text>] [--fixture <path>] [--api <url>]
59
+ agentkit channels deliveries list <name> [--api <url>]
60
+ agentkit channels deliveries show <delivery-id> [--api <url>]
61
+ agentkit inspect
62
+ agentkit build [--target cloudflare|container]
63
+ agentkit login --token <token>
64
+ agentkit logout
65
+ agentkit deploy [--target cloudflare|vps] [--host <host>] [--api <url>] [--dry-run] [--anonymous] [--local-wrangler] [--smoke <message>]
66
+ agentkit deploy doctor [--api <url>] [--anonymous]
67
+ agentkit deploy smoke [--message <text>] [--api <url>]
68
+ agentkit deploy status
69
+ agentkit deploy pause
70
+ agentkit deploy resume
71
+ agentkit secret set <NAME> <VALUE>
72
+ agentkit secret set <NAME> --stdin
73
+ agentkit secret set <NAME> --from-env [ENV_NAME]
74
+ agentkit secret set <NAME> --from-local-env
75
+ agentkit secret sync --from-local
76
+ agentkit secret list
77
+ agentkit secret unset <NAME>
78
+ agentkit access token create <name> [--api <url>] [--out <path>]
79
+ agentkit access token list
80
+ agentkit access token revoke <token-id>
81
+ agentkit env set <NAME> <VALUE>
82
+ agentkit env set <NAME> --stdin
83
+ agentkit env set <NAME> --from-env [ENV_NAME]
84
+ agentkit env list
85
+ agentkit env unset <NAME>
86
+ agentkit docs path
87
+ agentkit docs llms
88
+ agentkit docs full
89
+ agentkit handoff codex [goal]
90
+ agentkit handoff claude [goal]
91
+ agentkit help commands
92
+ ```
93
+
94
+ Prefer `env set --stdin` or `--from-env` for local secret values, and prefer `secret set --stdin`, `--from-env`, or `--from-local-env` for hosted secrets. Inline `<VALUE>` forms exist for simple non-sensitive values, but agents should avoid putting secrets in shell history.
95
+
96
+ Planned commands described by the contract but not implemented yet:
97
+
98
+ ```sh
99
+ agentkit eval create-from-conversation <conversation-id>
100
+ ```
101
+
102
+ ## Create And Test A Capsule
103
+
104
+ From a clean working directory:
105
+
106
+ ```sh
107
+ rm -rf /tmp/agentkit-demo
108
+ mkdir -p /tmp/agentkit-demo
109
+ cd /tmp/agentkit-demo
110
+
111
+ npx @andreprado/agentkit@alpha new demo --template blank
112
+ cd demo
113
+ npm run chat -- --message "hello"
114
+ npm run chat -- --message "second message"
115
+ npm run eval
116
+ npm run agentkit -- conversations list
117
+ npm run agentkit -- inspect
118
+ ```
119
+
120
+ Expected first chat output:
121
+
122
+ ```txt
123
+ Echo: hello
124
+ ```
125
+
126
+ The generated capsule includes `tsconfig.json` with `moduleResolution: "Bundler"` so TypeScript can resolve `@andreprado/agentkit`.
127
+ It also includes `AGENTS.md`, `AGENTKIT.md`, and `CLAUDE.md`, which tell coding agents to treat the owner's natural-language request as the brief.
128
+
129
+ The primary flow is:
130
+
131
+ ```sh
132
+ agentkit new eye-office-agent --template blank
133
+ cd eye-office-agent
134
+ ```
135
+
136
+ Then open the folder in Codex, Claude Code, or another coding agent and ask directly:
137
+
138
+ ```txt
139
+ Develop an appointment and intake agent for an ophthalmology office.
140
+ ```
141
+
142
+ The coding agent should infer the first useful version, edit `prompts/instructions.md`, `agentkit.config.ts`, `schema.sql`, `tools/`, and `evals/`, then run the verification commands before finishing. Do not wait for a wizard or recipe. AgentKit provides the scaffold and contract; the coding agent implements directly in the capsule.
143
+
144
+ Optional handoff shortcut:
145
+
146
+ ```sh
147
+ npm run agentkit -- handoff codex "Develop an appointment and intake agent for an ophthalmology office."
148
+ npm run agentkit -- handoff claude "Develop an appointment and intake agent for an ophthalmology office."
149
+ ```
150
+
151
+ The command prints a ready-to-paste prompt that points the coding agent at `AGENTKIT.md`, the repo-local `skills/agentkit-capsule/SKILL.md` router when present, and the packaged `llms.txt` docs router. Load `llms-full.txt` only when a skill or ambiguous framework behavior requires the complete contract.
152
+
153
+ The generated docs and handoff prompt must make UI testing explicit. For local UI testing, run `npm run dev`, open the printed `Chat:` URL, and tell the owner the exact URL. For hosted UI testing after deploy, run `npm run agentkit -- chat-ui --deploy`, open the printed `Chat:` URL, and tell the owner it is connected to the hosted deploy.
154
+
155
+ ## Agent Config
156
+
157
+ `agentkit.config.ts` is the source of truth:
158
+
159
+ ```ts
160
+ import { defineAgent } from "@andreprado/agentkit";
161
+
162
+ export default defineAgent({
163
+ name: "support-agent",
164
+ runtime: "edge",
165
+ provider: {
166
+ name: "test",
167
+ model: "fake",
168
+ },
169
+ instructions: "./prompts/instructions.md",
170
+ secrets: [],
171
+ tools: [],
172
+ access: {
173
+ mode: "private",
174
+ },
175
+ storage: {
176
+ driver: "agentkit",
177
+ },
178
+ });
179
+ ```
180
+
181
+ Valid runtime values:
182
+
183
+ ```txt
184
+ local
185
+ edge
186
+ ```
187
+
188
+ Valid provider names:
189
+
190
+ ```txt
191
+ test
192
+ openai
193
+ anthropic
194
+ openrouter
195
+ custom
196
+ ```
197
+
198
+ Current provider adapters:
199
+
200
+ ```txt
201
+ test/fake
202
+ openai via Pi SDK
203
+ anthropic via Pi SDK
204
+ openrouter via Pi SDK
205
+ ```
206
+
207
+ `custom` is a reserved config value. It is not implemented as a local provider adapter yet.
208
+
209
+ ## Provider Rules
210
+
211
+ Use `test/fake` for offline local tests:
212
+
213
+ ```ts
214
+ provider: {
215
+ name: "test",
216
+ model: "fake",
217
+ },
218
+ secrets: [],
219
+ ```
220
+
221
+ `test/fake` is deterministic. It is useful for scaffold checks, direct tool checks, and fake-provider evals, but it does not validate natural conversation quality.
222
+
223
+ Before claiming real conversation behavior has been tested, ask the owner which provider to use: OpenRouter, OpenAI, Anthropic, or another supported provider. Do not choose for them. After the owner chooses, update `agentkit.config.ts`, `.env.schema`, local secrets, hosted secrets if deploying, then rerun chat/UI checks.
224
+
225
+ OpenAI example:
226
+
227
+ ```ts
228
+ provider: {
229
+ name: "openai",
230
+ model: "gpt-4o-mini",
231
+ },
232
+ secrets: ["OPENAI_API_KEY"],
233
+ ```
234
+
235
+ Then keep the required name in `.env.schema`, put the value in ignored `.env`, and run AgentKit normally:
236
+
237
+ ```sh
238
+ npm run agentkit -- inspect
239
+ npm run chat -- --message "hello"
240
+ ```
241
+
242
+ `inspect` shows only names and set/missing status, never values. Do not commit `.env`. Generated `.gitignore` already excludes it.
243
+
244
+ If a provider key is missing, the runtime returns `secret_not_found`.
245
+
246
+ ## Knowledge Contract
247
+
248
+ Knowledge is AgentKit's native retrieval layer for facts the agent should ground in source files. Use it for FAQs, prices, policies, service descriptions, procedures, CSV tables, and reference docs. Do not put secrets, credentials, `.env` contents, or live customer/payment records in Knowledge. Use tools for live or authorization-sensitive data.
249
+
250
+ Configure Knowledge in `agentkit.config.ts`:
251
+
252
+ ```ts
253
+ knowledge: {
254
+ sources: [
255
+ "knowledge/faq.md",
256
+ { path: "knowledge/prices.csv", title: "Prices" },
257
+ ],
258
+ retrieval: {
259
+ topK: 8,
260
+ hybrid: false,
261
+ },
262
+ },
263
+ ```
264
+
265
+ Local Knowledge supports `.md`, `.markdown`, `.txt`, and `.csv` sources inside the Agent Capsule. Markdown chunks follow headings, text chunks follow paragraphs, and CSV chunks preserve row data with headers.
266
+
267
+ Embeddings are configured separately from the chat provider. The default provider is `none`, which gives local lexical search without an API key. For OpenAI embeddings:
268
+
269
+ ```ts
270
+ knowledge: {
271
+ sources: ["knowledge/faq.md"],
272
+ embedding: {
273
+ provider: "openai",
274
+ model: "text-embedding-3-small",
275
+ secret: "KNOWLEDGE_OPENAI_API_KEY",
276
+ },
277
+ retrieval: {
278
+ topK: 8,
279
+ hybrid: true,
280
+ },
281
+ },
282
+ ```
283
+
284
+ Set the local embedding secret with `agentkit env set KNOWLEDGE_OPENAI_API_KEY --stdin`. Do not commit the value.
285
+
286
+ Knowledge commands:
287
+
288
+ ```sh
289
+ agentkit knowledge add knowledge/faq.md
290
+ agentkit knowledge sync
291
+ agentkit knowledge inspect
292
+ agentkit knowledge search "refund policy" --top-k 3
293
+ ```
294
+
295
+ `knowledge add` indexes one local path. `knowledge sync` indexes all configured `knowledge.sources` and skips unchanged files by content hash. `agentkit dev` and `agentkit chat` also sync configured Knowledge automatically before local runs. `knowledge inspect` lists indexed sources and chunk counts. `knowledge search` validates retrieval before relying on the agent. When embeddings are configured locally, AgentKit stores canonical chunks in `.agentkit/agentkit.db`, rebuilds a local libSQL vector sidecar at `.agentkit/agentkit.vectors.db`, uses native `libsql_vector_idx` semantic search, and falls back to stored JSON embeddings if the native vector path is unavailable.
296
+
297
+ When `knowledge` is configured, AgentKit automatically registers the internal chat tool `agentkit_search_knowledge` and appends a prompt policy. The policy tells the agent to search before answering business-specific factual questions and not to expose raw retrieval JSON, scores, chunk IDs, or tool output objects. With `test/fake`, verify the internal tool directly:
298
+
299
+ ```sh
300
+ agentkit chat --message '{"tool":"agentkit_search_knowledge","input":{"query":"refund policy","topK":1}}'
301
+ ```
302
+
303
+ Expected output:
304
+
305
+ ```txt
306
+ Tool agentkit_search_knowledge: completed
307
+ ```
308
+
309
+ Cloudflare Knowledge deploys require `storage.driver: "agentkit"` and `storage.database.driver: "turso"`. `agentkit deploy doctor` and `agentkit build --target cloudflare` fail clearly when Knowledge is configured without Turso. Cloudflare artifacts include the Knowledge manifest, required embedding secret names, internal Knowledge schema, packaged local source contents, prompt policy, and hosted `agentkit_search_knowledge` runtime. During `agentkit deploy`, AgentKit Cloud applies the Knowledge schema, chunks packaged local sources, creates embeddings when configured, deletes stale hosted sources, and syncs sources, chunks, embedding metadata, FTS rows, and a native Turso `libsql_vector_idx` index into the project Turso database before publishing the Worker. Local `agentkit knowledge add/sync`, `agentkit dev`, and `agentkit chat` index configured Knowledge into local SQLite and the local libSQL vector sidecar; hosted deploy syncs configured local Knowledge sources automatically from the deploy artifact so private source material and embedding secrets do not move into client code. Hosted semantic search uses Turso native vector search when embeddings are configured and falls back to stored JSON embeddings if the native vector path is unavailable.
310
+
311
+ Full guide: `docs/guides/add-knowledge.md`.
312
+
313
+ ## Channel Contract
314
+
315
+ Channels are hosted inbound/outbound conversation transports. They are separate from tools: channels receive user messages, while tools let the agent call external systems.
316
+
317
+ Use these helpers in `agentkit.config.ts`:
318
+
319
+ ```ts
320
+ import { defineAgent, telegramChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
321
+
322
+ export default defineAgent({
323
+ name: "support-agent",
324
+ runtime: "edge",
325
+ provider: { name: "test", model: "fake" },
326
+ instructions: "./prompts/instructions.md",
327
+ secrets: [],
328
+ tools: [],
329
+ channels: [
330
+ websiteChannel({ name: "website-chat" }),
331
+ telegramChannel({ name: "support-telegram" }),
332
+ whatsappChannel({ name: "support-whatsapp", provider: "zapster" }),
333
+ ],
334
+ access: { mode: "public" },
335
+ storage: { driver: "agentkit" },
336
+ });
337
+ ```
338
+
339
+ Rules:
340
+
341
+ - `runtime: "edge"` is required when `channels` are configured.
342
+ - Channel names are stable lowercase identifiers and must be unique.
343
+ - Config stores secret names only, never secret values.
344
+ - AgentKit owns channel webhook URLs, dedupe, identities, queue state, and delivery logs.
345
+ - Do not store channel plumbing in the user's Turso database.
346
+ - Use `buffer.mode: "debounce"` when a channel should coalesce rapid client messages into one agent run.
347
+ - Buffered deliveries show `buffered`, then flush to one `queued` run after `quietWindowMs`, `maxWaitMs`, `maxMessages`, or `maxChars`.
348
+
349
+ Channel buffer example:
350
+
351
+ ```ts
352
+ whatsappChannel({
353
+ name: "support-whatsapp",
354
+ provider: "zapster",
355
+ buffer: {
356
+ mode: "debounce",
357
+ quietWindowMs: 2500,
358
+ maxWaitMs: 12000,
359
+ maxMessages: 20,
360
+ maxChars: 8000,
361
+ },
362
+ })
363
+ ```
364
+
365
+ Useful guides:
366
+
367
+ - Add a channel: `docs/guides/add-channel.md`
368
+ - Connect Telegram: `docs/guides/connect-telegram.md`
369
+ - Connect WhatsApp through Zapster: `docs/guides/connect-whatsapp-zapster.md`
370
+ - Debug a channel: `docs/guides/debug-channel.md`
371
+ - Channel security: `docs/guides/channel-security.md`
372
+ - Production handoff: `docs/guides/channels-production-handoff.md`
373
+
374
+ Telegram required secrets:
375
+
376
+ ```txt
377
+ TELEGRAM_BOT_TOKEN
378
+ TELEGRAM_WEBHOOK_SECRET
379
+ ```
380
+
381
+ Zapster WhatsApp required secrets:
382
+
383
+ ```txt
384
+ ZAPSTER_API_KEY
385
+ ZAPSTER_INSTANCE_ID
386
+ ZAPSTER_WEBHOOK_ID
387
+ ```
388
+
389
+ Common channel verification:
390
+
391
+ ```sh
392
+ agentkit inspect
393
+ agentkit deploy
394
+ agentkit channels list
395
+ agentkit channels add telegram support-telegram
396
+ agentkit channels setup support-telegram
397
+ agentkit channels test support-telegram --message "hello"
398
+ agentkit channels deliveries list support-telegram
399
+ agentkit channels deliveries show <delivery-id>
400
+ ```
401
+
402
+ `channels setup` is read-only by default. `channels setup <telegram-name> --apply` calls Telegram `setWebhook` and requires `TELEGRAM_BOT_TOKEN` plus `TELEGRAM_WEBHOOK_SECRET`.
403
+
404
+ Default tests are offline. Real provider smoke tests are opt-in:
405
+
406
+ ```sh
407
+ AGENTKIT_RUN_TELEGRAM_CHANNEL_TESTS=1 bun test
408
+ AGENTKIT_RUN_ZAPSTER_CHANNEL_TESTS=1 bun test
409
+ ```
410
+
411
+ Telegram smoke also requires `TELEGRAM_BOT_TOKEN`, `TELEGRAM_WEBHOOK_SECRET`, and `AGENTKIT_TELEGRAM_WEBHOOK_URL`.
412
+ Zapster smoke also requires `ZAPSTER_API_KEY`, `AGENTKIT_ZAPSTER_SEND_URL`, and `AGENTKIT_ZAPSTER_TO`.
413
+
414
+ ## Tool Contract
415
+
416
+ Tools are generic TypeScript objects created with `defineTool`.
417
+
418
+ Example:
419
+
420
+ ```ts
421
+ import { defineTool } from "@andreprado/agentkit";
422
+
423
+ export const lookupOrder = defineTool({
424
+ name: "lookup_order",
425
+ description: "Looks up an order by id.",
426
+ inputSchema: {
427
+ type: "object",
428
+ properties: {
429
+ orderId: { type: "string" },
430
+ },
431
+ required: ["orderId"],
432
+ additionalProperties: false,
433
+ },
434
+ outputSchema: {
435
+ type: "object",
436
+ properties: {
437
+ orderId: { type: "string" },
438
+ found: { type: "boolean" },
439
+ status: { type: "string" },
440
+ },
441
+ required: ["orderId", "found", "status"],
442
+ },
443
+ secrets: ["ORDER_API_KEY"],
444
+ timeoutMs: 30000,
445
+ async execute(input: { orderId: string }, ctx) {
446
+ const key = ctx.secrets.ORDER_API_KEY;
447
+ return { orderId: input.orderId, found: true, status: "shipped" };
448
+ },
449
+ });
450
+ ```
451
+
452
+ Register the tool in `agentkit.config.ts`:
453
+
454
+ ```ts
455
+ import { lookupOrder } from "./tools/lookup-order";
456
+
457
+ export default defineAgent({
458
+ tools: [lookupOrder],
459
+ });
460
+ ```
461
+
462
+ Tool runtime rules:
463
+
464
+ - input schema is validated before execution;
465
+ - output schema is validated when `outputSchema` exists;
466
+ - `type` can be a string or JSON Schema union such as `["string", "null"]`;
467
+ - optional object properties sent as `null` are treated as omitted unless the property schema allows `null`;
468
+ - a tool receives only secrets listed in its own `secrets` field;
469
+ - default timeout is 30000 ms;
470
+ - `timeoutMs` overrides the default;
471
+ - tool calls are saved in AgentKit-managed local storage;
472
+ - secret values are redacted before storage.
473
+ - tools that need SQL use canonical `ctx.db`; `ctx.database` and `ctx.storage.sql` are supported aliases;
474
+ - tools can use `ctx.db.batch([...])` for atomic writes; local tools can also use `ctx.db.transaction(async (tx) => ...)`;
475
+ - tools can inspect `ctx.runtime` with `{ environment, invocation, target, database }`;
476
+ - tools must not import local database drivers or Node-only APIs. Use AgentKit runtime services instead.
477
+
478
+ ## Database Tools And Dual Storage
479
+
480
+ For agent-owned application tables, `schema.sql` is the single source of truth.
481
+
482
+ Keep `storage.driver: "agentkit"`. If the generated capsule includes a managed database schema field, keep it pointed at `./schema.sql`.
483
+
484
+ Local behavior:
485
+
486
+ - `agentkit chat`, `agentkit tool`, and `agentkit dev` use AgentKit-managed local storage.
487
+ - before a tool runs, AgentKit applies `schema.sql` locally;
488
+ - use `agentkit db migrate`, `agentkit db reset --yes`, `agentkit db seed [--file seed.sql]`, and `agentkit db shell` for local setup and inspection.
489
+
490
+ Hosted behavior:
491
+
492
+ - `agentkit deploy` builds and deploys the capsule;
493
+ - AgentKit migrates/provisions hosted storage internally and applies the same `schema.sql`;
494
+ - the user should not create hosted databases, buckets, or runtimes manually.
495
+
496
+ Example `schema.sql`:
497
+
498
+ ```sql
499
+ CREATE TABLE IF NOT EXISTS appointments (
500
+ id TEXT PRIMARY KEY,
501
+ client_name TEXT NOT NULL,
502
+ starts_at TEXT NOT NULL,
503
+ notes TEXT,
504
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
505
+ UNIQUE (starts_at)
506
+ );
507
+ ```
508
+
509
+ `schema.sql` is an idempotent bootstrap file in v1. Use `CREATE TABLE IF NOT EXISTS`, `CREATE INDEX IF NOT EXISTS`, and only safe additive `ALTER TABLE` statements. AgentKit does not automatically run destructive changes or ordered `migrations/*.sql` yet.
510
+
511
+ Example tool:
512
+
513
+ ```ts
514
+ import { defineTool } from "@andreprado/agentkit";
515
+
516
+ export const scheduleAppointment = defineTool({
517
+ name: "schedule_appointment",
518
+ description: "Schedules an appointment in the agent database.",
519
+ inputSchema: {
520
+ type: "object",
521
+ properties: {
522
+ clientName: { type: "string" },
523
+ startsAt: { type: "string" },
524
+ notes: { type: "string" },
525
+ },
526
+ required: ["clientName", "startsAt"],
527
+ additionalProperties: false,
528
+ },
529
+ async execute(input: { clientName: string; startsAt: string; notes?: string }, ctx) {
530
+ const id = crypto.randomUUID();
531
+
532
+ await ctx.db.execute(
533
+ "INSERT INTO appointments (id, client_name, starts_at, notes) VALUES (?, ?, ?, ?)",
534
+ [id, input.clientName, input.startsAt, input.notes ?? null],
535
+ );
536
+
537
+ const result = await ctx.db.query("SELECT id, client_name, starts_at FROM appointments WHERE id = ?", [id]);
538
+ const appointment = result.rows[0];
539
+
540
+ return {
541
+ id: String(appointment.id),
542
+ clientName: String(appointment.client_name),
543
+ startsAt: String(appointment.starts_at),
544
+ };
545
+ },
546
+ });
547
+ ```
548
+
549
+ Local test:
550
+
551
+ ```sh
552
+ npm run agentkit -- tool schedule_appointment --input '{"clientName":"Ada Lovelace","startsAt":"2026-06-01T10:00:00Z"}'
553
+ npm run agentkit -- db shell
554
+ ```
555
+
556
+ Run a registered tool directly:
557
+
558
+ ```sh
559
+ npm run agentkit -- tool lookup_order --input '{"orderId":"A100"}'
560
+ ```
561
+
562
+ ## Local Storage
563
+
564
+ SQLite storage lives at:
565
+
566
+ ```txt
567
+ .agentkit/agentkit.db
568
+ ```
569
+
570
+ Tables:
571
+
572
+ ```txt
573
+ conversations
574
+ messages
575
+ runs
576
+ tool_calls
577
+ agentkit_migrations
578
+ ```
579
+
580
+ Agent-owned tables from `schema.sql` live in the same SQLite file locally. Runtime state is local and must not be committed.
581
+
582
+ ## Inspect Contract
583
+
584
+ Run:
585
+
586
+ ```sh
587
+ agentkit inspect
588
+ ```
589
+
590
+ Example output:
591
+
592
+ ```json
593
+ {
594
+ "agent": "demo",
595
+ "runtime": "local",
596
+ "provider": {
597
+ "name": "test",
598
+ "model": "fake"
599
+ },
600
+ "prompt": "prompts/instructions.md",
601
+ "tools": [],
602
+ "access": {
603
+ "mode": "private"
604
+ },
605
+ "storage": ".agentkit/agentkit.db",
606
+ "database": {
607
+ "local": {
608
+ "driver": "sqlite",
609
+ "path": ".agentkit/agentkit.db",
610
+ "schema": "./schema.sql"
611
+ },
612
+ "hosted": {
613
+ "driver": "turso",
614
+ "provisioning": "agentkit-managed",
615
+ "schema": "./schema.sql"
616
+ }
617
+ },
618
+ "secrets": {},
619
+ "managedSecrets": ["TURSO_AUTH_TOKEN", "TURSO_DATABASE_URL"],
620
+ "userSecrets": [],
621
+ "runtimeContract": {
622
+ "local": {
623
+ "environment": "local",
624
+ "target": "bun",
625
+ "database": "sqlite"
626
+ },
627
+ "hosted": {
628
+ "environment": "hosted",
629
+ "target": "cloudflare",
630
+ "database": "turso",
631
+ "providerSupported": true
632
+ },
633
+ "aliases": ["ctx.db", "ctx.database", "ctx.storage.sql"]
634
+ }
635
+ }
636
+ ```
637
+
638
+ Secret values never appear. Each declared user secret appears as `set` or `missing`. `managedSecrets` are provisioned and injected by AgentKit Cloud; users do not put those values in local `.env`.
639
+
640
+ ## Dev Server Contract
641
+
642
+ Run:
643
+
644
+ ```sh
645
+ agentkit dev
646
+ ```
647
+
648
+ If the default local port is occupied, `agentkit dev` chooses the next available port and prints the actual URLs. If the occupied port is another AgentKit server, the output names the agent using it.
649
+
650
+ Expected output:
651
+
652
+ ```txt
653
+ Agent Capsule running
654
+
655
+ Chat: http://localhost:4123
656
+ API: http://localhost:4123/v1/chat
657
+ Inspect: http://localhost:4123/_agentkit
658
+ Storage: .agentkit/agentkit.db
659
+ ```
660
+
661
+ To reopen the local UI for the current capsule after the server is already running:
662
+
663
+ ```sh
664
+ agentkit open
665
+ ```
666
+
667
+ Endpoints:
668
+
669
+ ```txt
670
+ GET /_agentkit
671
+ POST /v1/chat
672
+ GET /v1/conversations
673
+ GET /v1/conversations/:id
674
+ ```
675
+
676
+ Chat request:
677
+
678
+ ```sh
679
+ curl -X POST http://localhost:4123/v1/chat \
680
+ -H 'content-type: application/json' \
681
+ -d '{"message":{"role":"user","content":"hello"}}'
682
+ ```
683
+
684
+ The chat response includes `conversationId`. Send the same `conversationId` on the next `POST /v1/chat` request, or pass it to `agentkit chat --conversation-id <id>`, to continue with the persisted message history.
685
+
686
+ ## Conversations
687
+
688
+ After chat:
689
+
690
+ ```sh
691
+ agentkit conversations list
692
+ agentkit conversations show <conversation-id>
693
+ ```
694
+
695
+ List output columns:
696
+
697
+ ```txt
698
+ id title updated_at messages
699
+ ```
700
+
701
+ Show output includes the conversation id, title, updated timestamp, and each message as `role: content`.
702
+
703
+ ## Evals
704
+
705
+ Generated capsules include:
706
+
707
+ ```txt
708
+ evals/smoke.eval.ts
709
+ ```
710
+
711
+ Run local evals:
712
+
713
+ ```sh
714
+ npm run eval
715
+ ```
716
+
717
+ Supported assertion types:
718
+
719
+ ```txt
720
+ contains
721
+ not_contains
722
+ regex
723
+ matches_regex
724
+ persisted_tool_call
725
+ ```
726
+
727
+ `persisted_tool_call` validates the tool call saved in local SQLite `tool_calls`, not a provider-specific raw response shape. It can be a tool name string or an object with `name`, `input`, `output`, `status`, and/or `visibility`. `tool_call` remains accepted as a backwards-compatible alias.
728
+
729
+ Evals run the normal capsule tools. If a tool would write externally, delete, charge money, send email, or call a real customer system, make its `execute` implementation branch on `ctx.runtime.environment === "eval"` and return deterministic non-destructive output for eval runs. Do not invent an eval-only mock API; keep the behavior inside the registered tool contract unless AgentKit adds a first-class mock facility later.
730
+
731
+ ## Security Rules
732
+
733
+ Never commit:
734
+
735
+ ```txt
736
+ .env
737
+ .agentkit/
738
+ node_modules/
739
+ ```
740
+
741
+ Do not store secret values in:
742
+
743
+ ```txt
744
+ agentkit.config.ts
745
+ .env.schema
746
+ AGENTS.md
747
+ CLAUDE.md
748
+ README.md
749
+ evals/
750
+ prompts/
751
+ docs/
752
+ ```
753
+
754
+ Local `.env` is development only. Use `.env.schema` as the committed secret-name contract; local AgentKit commands load `.env` directly. Hosted alpha deploys use `agentkit login --token ...` and managed secrets through `agentkit secret set/list/unset` or `agentkit secret sync --from-local`. Prefer `--stdin`, `--from-env`, `--from-local-env`, or sync from local `.env` so secret values do not appear in shell history. Inline `<VALUE>` forms exist only for compatibility and simple non-sensitive values.
755
+
756
+ Tools are a security boundary. A tool must declare every secret it needs. The runtime injects only tool-declared secrets.
757
+
758
+ ## Hosted Deploy Contract
759
+
760
+ For the coding agent and user, deploy is one command. Do not ask the user to choose a hosting target.
761
+
762
+ Current flow:
763
+
764
+ ```sh
765
+ agentkit deploy --dry-run
766
+ agentkit login --token agk_user_...
767
+ agentkit deploy doctor
768
+ agentkit deploy --smoke "hello"
769
+ agentkit deploy status
770
+ agentkit deploy smoke --message "hello"
771
+ agentkit chat-ui --deploy
772
+ ```
773
+
774
+ `agentkit deploy doctor` checks AgentKit Cloud login, `cloudflare_deploy_alpha`, online deploy capacity, hosted secrets, local `.env` names that still need `agentkit secret set`, and private-access runtime token handling. `agentkit deploy` sends the capsule to AgentKit Cloud, runs the same readiness check automatically before building and uploading, and writes the local chat/UI deploy access token to `.agentkit/chat-access-token.json` for private hosted deploys. `agentkit deploy --smoke "hello"` deploys and then tests `/v1/chat` with the deploy access token. `agentkit deploy smoke --message "hello"` repeats that smoke against the last local deploy. `agentkit chat-ui --deploy` serves a local UI pointed at the hosted deploy using that token without exposing it to browser code. Production alpha deploys require an account with `cloudflare_deploy_alpha`; local commands and dry-run builds do not require login. AgentKit owns infrastructure selection, backend migration, managed secrets, and public URL creation.
775
+
776
+ The CLI defaults to the hosted AgentKit Cloud API at `https://agentkit-cloud.aibuilders.com.br`. Use `AGENTKIT_CLOUD_API_URL` or `agentkit deploy --api <url>` only for local or alternate control-plane tests.
777
+
778
+ Account/access flow:
779
+
780
+ ```sh
781
+ agentkit secret set OPENAI_API_KEY --from-local-env
782
+ agentkit secret sync --from-local
783
+ agentkit secret list
784
+ agentkit access token create website-chat --out .agentkit/website-chat-access-token.json
785
+ agentkit access token list
786
+ ```
787
+
788
+ Production storage uses `storage.driver: "agentkit"`. `.env` is never uploaded.
789
+
790
+ Hosted backend responses use this error envelope:
791
+
792
+ ```json
793
+ {
794
+ "error": {
795
+ "code": "secret_not_found",
796
+ "message": "Secret OPENAI_API_KEY is not set for this deploy.",
797
+ "request_id": "req_123",
798
+ "details": {
799
+ "secret": "OPENAI_API_KEY"
800
+ }
801
+ }
802
+ }
803
+ ```
804
+
805
+ Common hosted error codes:
806
+
807
+ ```txt
808
+ unauthorized
809
+ forbidden
810
+ not_found
811
+ validation_error
812
+ conflict
813
+ rate_limited
814
+ quota_exceeded
815
+ secret_not_found
816
+ access_token_invalid
817
+ deploy_not_ready
818
+ deploy_paused
819
+ tool_timeout
820
+ provider_error
821
+ internal_error
822
+ ```
823
+
824
+ ## Troubleshooting
825
+
826
+ Missing `@andreprado/agentkit` types:
827
+
828
+ ```sh
829
+ npm install
830
+ npm run typecheck
831
+ ```
832
+
833
+ `agentkit new` installs dependencies by default. Run this if the scaffold used `--no-install`, the install failed, or `node_modules` was deleted.
834
+
835
+ Make sure `tsconfig.json` contains:
836
+
837
+ ```json
838
+ {
839
+ "compilerOptions": {
840
+ "moduleResolution": "Bundler",
841
+ "types": ["node"]
842
+ }
843
+ }
844
+ ```
845
+
846
+ Missing config:
847
+
848
+ ```txt
849
+ No agentkit.config.ts found
850
+ ```
851
+
852
+ Run the command from the capsule root.
853
+
854
+ Missing prompt:
855
+
856
+ ```txt
857
+ Prompt file not found
858
+ ```
859
+
860
+ Check `instructions` in `agentkit.config.ts`.
861
+
862
+ Missing provider key:
863
+
864
+ ```txt
865
+ secret_not_found
866
+ ```
867
+
868
+ Add the required name to `.env` locally. Do not commit the value.
869
+
870
+ Tool validation error:
871
+
872
+ ```txt
873
+ tool_validation_error
874
+ ```
875
+
876
+ Check the tool call input against `inputSchema`.