@andreprado/agentkit 0.1.0-alpha.8 → 0.1.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.
Files changed (117) hide show
  1. package/README.md +18 -1
  2. package/docs/guides/add-channel.md +251 -7
  3. package/docs/guides/add-knowledge.md +10 -0
  4. package/docs/guides/add-managed-composio.md +165 -0
  5. package/docs/guides/add-tool.md +10 -3
  6. package/docs/guides/channel-security.md +162 -32
  7. package/docs/guides/connect-discord.md +178 -0
  8. package/docs/guides/connect-slack.md +126 -0
  9. package/docs/guides/connect-telegram.md +61 -1
  10. package/docs/guides/connect-whatsapp-evolution.md +121 -0
  11. package/docs/guides/connect-whatsapp-uazapi.md +139 -0
  12. package/docs/guides/connect-whatsapp-zapster.md +119 -16
  13. package/docs/guides/create-agent.md +31 -4
  14. package/docs/guides/debug-channel.md +159 -0
  15. package/docs/guides/improve-from-production.md +151 -0
  16. package/docs/guides/prepare-deploy.md +32 -14
  17. package/docs/guides/replay-production-traces.md +72 -0
  18. package/docs/guides/run-evals.md +95 -25
  19. package/docs/guides/security-rules.md +9 -5
  20. package/docs/guides/send-feedback.md +135 -0
  21. package/docs/guides/use-jev.md +67 -0
  22. package/docs/guides/use-provider.md +70 -3
  23. package/docs/llms-full.txt +295 -25
  24. package/docs/llms.txt +54 -7
  25. package/package.json +3 -7
  26. package/src/cli/args.ts +23 -2
  27. package/src/cli/cloud-client.ts +121 -9
  28. package/src/cli/commands/channels.ts +1185 -50
  29. package/src/cli/commands/feedback.ts +438 -0
  30. package/src/cli/commands/provider.ts +47 -0
  31. package/src/cli/commands/transcribe.ts +171 -0
  32. package/src/cli/deploy-chat-ui.ts +232 -18
  33. package/src/cli/deploy-readiness.ts +227 -14
  34. package/src/cli/help.ts +68 -8
  35. package/src/cli/index.ts +740 -35
  36. package/src/cli/new-command.ts +41 -0
  37. package/src/cloud/client.ts +4 -3
  38. package/src/cloud/contracts.ts +1 -1
  39. package/src/create-project.ts +18 -35
  40. package/src/index.ts +565 -11
  41. package/src/providers/codex-auth.ts +111 -0
  42. package/src/providers/pi.ts +88 -19
  43. package/src/providers/test.ts +36 -0
  44. package/src/providers/types.ts +8 -0
  45. package/src/runtime/channel-test-harness.ts +21 -1
  46. package/src/runtime/channels/discord.ts +896 -0
  47. package/src/runtime/channels/generic-webhook.ts +974 -0
  48. package/src/runtime/channels/slack.ts +646 -0
  49. package/src/runtime/channels/telegram.ts +466 -23
  50. package/src/runtime/channels/whatsapp-evolution.ts +1357 -0
  51. package/src/runtime/channels/whatsapp-meta.ts +9 -0
  52. package/src/runtime/channels/whatsapp-uazapi.ts +1323 -0
  53. package/src/runtime/channels/whatsapp-zapster.ts +674 -40
  54. package/src/runtime/channels.ts +89 -4
  55. package/src/runtime/chat.ts +70 -44
  56. package/src/runtime/config.ts +489 -20
  57. package/src/runtime/core/manifest.ts +75 -5
  58. package/src/runtime/core/targets.ts +5 -5
  59. package/src/runtime/deploy-readiness.ts +34 -4
  60. package/src/runtime/dev-server.ts +639 -39
  61. package/src/runtime/env.ts +8 -3
  62. package/src/runtime/evals.ts +445 -74
  63. package/src/runtime/improve.ts +868 -0
  64. package/src/runtime/inspect.ts +173 -4
  65. package/src/runtime/integrations/composio.ts +425 -0
  66. package/src/runtime/knowledge/retrieve.ts +25 -5
  67. package/src/runtime/knowledge/schema.ts +45 -1
  68. package/src/runtime/prompt-context.ts +141 -0
  69. package/src/runtime/runtime-contract.ts +71 -7
  70. package/src/runtime/skills.ts +95 -0
  71. package/src/runtime/targets/cloudflare/build.ts +1010 -208
  72. package/src/runtime/targets/container/server.ts +1 -1
  73. package/src/runtime/targets/vps/deploy.ts +26 -9
  74. package/src/runtime/tool-runner.ts +9 -1
  75. package/src/runtime/tools.ts +26 -2
  76. package/src/runtime/transcription.ts +483 -0
  77. package/src/storage/sqlite.ts +7 -2
  78. package/src/templates/blank.ts +37 -9
  79. package/src/templates/dentista.ts +40 -14
  80. package/src/templates/skills/agentkit-build-agent/SKILL.md +34 -5
  81. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +2 -1
  82. package/src/templates/skills/agentkit-capsule/SKILL.md +32 -3
  83. package/src/templates/skills/agentkit-capsule/references/docs-router.md +2 -2
  84. package/src/templates/skills/agentkit-channels/SKILL.md +71 -6
  85. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +9 -2
  86. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +34 -5
  87. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  88. package/src/templates/skills/agentkit-channels/references/slack.md +56 -0
  89. package/src/templates/skills/agentkit-channels/references/telegram.md +39 -4
  90. package/src/templates/skills/agentkit-channels/references/whatsapp-evolution.md +57 -0
  91. package/src/templates/skills/agentkit-channels/references/whatsapp-uazapi.md +54 -0
  92. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +42 -8
  93. package/src/templates/skills/agentkit-database/SKILL.md +11 -0
  94. package/src/templates/skills/agentkit-deploy/SKILL.md +9 -1
  95. package/src/templates/skills/agentkit-evals/SKILL.md +77 -13
  96. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +13 -6
  97. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +8 -4
  98. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +8 -4
  99. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +16 -7
  100. package/src/templates/skills/agentkit-improve/SKILL.md +96 -0
  101. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  102. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  103. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  104. package/src/templates/skills/agentkit-integrations/SKILL.md +98 -0
  105. package/src/templates/skills/agentkit-knowledge/SKILL.md +4 -1
  106. package/src/templates/skills/agentkit-prompts/SKILL.md +3 -1
  107. package/src/templates/skills/agentkit-provider/SKILL.md +29 -4
  108. package/src/templates/skills/agentkit-security/SKILL.md +5 -2
  109. package/src/templates/skills/agentkit-tools/SKILL.md +8 -1
  110. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +8 -8
  111. package/src/templates/skills/agentkit-tools/examples/jev-service-fit.tool.md +110 -0
  112. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +25 -1
  113. package/src/templates/support.ts +42 -12
  114. package/docs/guides/agentkit-skills-architecture.md +0 -471
  115. package/docs/guides/channels-implementation-map.md +0 -243
  116. package/docs/guides/channels-production-handoff.md +0 -101
  117. package/docs/portable-deploy-release-checklist.md +0 -41
@@ -33,7 +33,8 @@ The capsule root is the runtime boundary. Run AgentKit commands from the directo
33
33
  Current commands:
34
34
 
35
35
  ```sh
36
- agentkit new <name> [--template blank|support|dentista] [--no-install]
36
+ agentkit new [name] [--template blank|support|dentista] [--no-install]
37
+ agentkit new .
37
38
  agentkit dev [--port <number>]
38
39
  agentkit open
39
40
  agentkit chat-ui --deploy
@@ -49,25 +50,48 @@ agentkit db reset --yes
49
50
  agentkit db shell
50
51
  agentkit db seed [--file <path>]
51
52
  agentkit eval run
53
+ agentkit eval from-conversation <conversation-id> [--out <path>] [--force]
54
+ agentkit improve collect [--deploy] [--since <duration|iso>] [--conversation-id <id>] [--out <directory>]
55
+ agentkit improve evals <bundle-dir-or-json> [--force]
56
+ agentkit replay <bundle-dir-or-json> --against local
57
+ agentkit feedback create [--about last-run|deploy|manual] [--kind bug|confusion|missing_docs|feature_request|deploy_issue|runtime_issue|other] --summary <text> [--message <text>] [--out <path>]
58
+ agentkit feedback preview [draft.json]
59
+ agentkit feedback send [draft.json] [--about last-run|deploy|manual] [--kind <kind>] --summary <text> [--message <text>] [--api <url>] [--save]
52
60
  agentkit conversations list
53
61
  agentkit conversations show <conversation-id>
62
+ agentkit conversations trace <conversation-id> [--deploy]
54
63
  agentkit channels list
55
- agentkit channels add <website|telegram|whatsapp> <name> [--provider zapster|meta] [--api <url>]
64
+ agentkit channels add <website|telegram|whatsapp|discord|slack|webhook> <name> [--provider zapster|meta|uazapi|evolution] [--mode interactions|bot] [--api <url>]
65
+ agentkit channels connect <website|telegram|whatsapp|discord|slack|webhook> <name> [--provider zapster|meta|uazapi|evolution] [--mode interactions|bot] [--api <url>]
56
66
  agentkit channels setup <name> [--apply] [--api <url>]
57
67
  agentkit channels status <name> [--api <url>]
58
68
  agentkit channels test <name> [--message <text>] [--fixture <path>] [--api <url>]
69
+ agentkit channels test-audio <name> [--fixture voice-note|audio-file|<path>] [--api <url>]
59
70
  agentkit channels deliveries list <name> [--api <url>]
60
71
  agentkit channels deliveries show <delivery-id> [--api <url>]
72
+ agentkit integrations status [--toolkit <slug>] [--api <url>]
73
+ agentkit integrations connect composio [--toolkit <slug>] [--callback-url <url>] [--api <url>]
74
+ agentkit skills status
75
+ agentkit skills sync
61
76
  agentkit inspect
62
77
  agentkit build [--target cloudflare|container]
78
+ agentkit billing checkout --slots <count> [--email <email>] [--api <url>]
79
+ agentkit billing status <billing-intent-id> --secret <secret> [--api <url>]
80
+ agentkit billing claim <billing-intent-id> --secret <secret> [--token-name <name>] [--api <url>]
81
+ agentkit billing portal [--api <url>]
82
+ agentkit provider login|status|logout openai-codex
63
83
  agentkit login --token <token>
64
84
  agentkit logout
85
+ agentkit account token create <name> [--api <url>] [--use] [--out <path>]
86
+ agentkit account token list [--api <url>]
87
+ agentkit account token revoke <token-id> [--api <url>]
65
88
  agentkit deploy [--target cloudflare|vps] [--host <host>] [--api <url>] [--dry-run] [--anonymous] [--local-wrangler] [--smoke <message>]
66
89
  agentkit deploy doctor [--api <url>] [--anonymous]
67
90
  agentkit deploy smoke [--message <text>] [--api <url>]
68
91
  agentkit deploy status
69
92
  agentkit deploy pause
70
93
  agentkit deploy resume
94
+ agentkit transcribe smoke [--provider test|openai|groq] [--model <model>] [--fixture <audio-file>]
71
95
  agentkit secret set <NAME> <VALUE>
72
96
  agentkit secret set <NAME> --stdin
73
97
  agentkit secret set <NAME> --from-env [ENV_NAME]
@@ -93,11 +117,11 @@ agentkit help commands
93
117
 
94
118
  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
119
 
96
- Planned commands described by the contract but not implemented yet:
120
+ Use `agentkit feedback create` when AgentKit itself fails, confuses the coding agent, or lacks docs. Drafts are local files under `.agentkit/feedback/` and are not sent automatically. Use `agentkit feedback send` only after reviewing the draft and logging in with `agentkit login --token agk_user_...`. Feedback upload uses authenticated AgentKit Cloud account auth, redacts common token/key patterns, does not upload arbitrary files, and does not cause the deployed agent runtime to phone home.
97
121
 
98
- ```sh
99
- agentkit eval create-from-conversation <conversation-id>
100
- ```
122
+ On Windows PowerShell, if `npm.ps1` or `npx.ps1` is blocked with `PSSecurityException`, run capsule scripts through the `.cmd` shims instead of changing the workflow. Examples: `npx.cmd @andreprado/agentkit@alpha new demo --template blank`, `npm.cmd run agentkit -- inspect`, `npm.cmd run agentkit -- knowledge sync`, and `npm.cmd run eval`.
123
+
124
+ Managed Composio is configured with `composioManaged({...})` in `agentkit.config.ts` and is paid hosted AgentKit infrastructure. It requires a non-anonymous AgentKit Cloud deploy with `managed_composio`, uses one Composio settings profile per agent, injects `COMPOSIO_API_KEY` as an AgentKit-managed secret, resolves toolkit auth configs from AgentKit Cloud, validates toolkit readiness during `agentkit deploy doctor`, and exposes the generated `agentkit_composio_execute` tool only for explicit configured action slugs. Calendar starters should include `GOOGLECALENDAR_EVENTS_LIST`, `GOOGLECALENDAR_CREATE_EVENT`, and `GOOGLECALENDAR_UPDATE_EVENT`; create-event calls must pass UTC `start_datetime` plus explicit duration. An integration containing external write actions is operator-only; invoke it directly with `agentkit tool`, and pass `confirmed: true` for writes unless the integration disables that secondary check. See `docs/guides/add-managed-composio.md`.
101
125
 
102
126
  ## Create And Test A Capsule
103
127
 
@@ -117,6 +141,8 @@ npm run agentkit -- conversations list
117
141
  npm run agentkit -- inspect
118
142
  ```
119
143
 
144
+ Run `agentkit new` without a name in an interactive terminal to be prompted for the project folder. Use `agentkit new .` to create the capsule in the current directory. Non-interactive scripts should pass a name or `.` explicitly.
145
+
120
146
  Expected first chat output:
121
147
 
122
148
  ```txt
@@ -139,7 +165,7 @@ Then open the folder in Codex, Claude Code, or another coding agent and ask dire
139
165
  Develop an appointment and intake agent for an ophthalmology office.
140
166
  ```
141
167
 
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.
168
+ 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 send the owner back to a CLI brief wizard. AgentKit provides the scaffold, contract, and skills; the coding agent implements directly in the capsule from the owner's chat message.
143
169
 
144
170
  Optional handoff shortcut:
145
171
 
@@ -166,6 +192,7 @@ export default defineAgent({
166
192
  name: "test",
167
193
  model: "fake",
168
194
  },
195
+ timeZone: "America/New_York",
169
196
  instructions: "./prompts/instructions.md",
170
197
  secrets: [],
171
198
  tools: [],
@@ -178,6 +205,8 @@ export default defineAgent({
178
205
  });
179
206
  ```
180
207
 
208
+ `timeZone` is optional and must be an IANA time zone when set. AgentKit injects dynamic runtime context into every chat run: current ISO timestamp, local date, local weekday, local date/time, and timezone. Use `timeZone` for scheduling, appointments, reminders, deadlines, and any prompt behavior that interprets "today", "tomorrow", weekdays, or relative dates. Do not hardcode today's date in `prompts/instructions.md`. If `timeZone` is omitted, AgentKit falls back to `AGENTKIT_TIME_ZONE`, then valid `TZ`, then the runtime default timezone.
209
+
181
210
  Valid runtime values:
182
211
 
183
212
  ```txt
@@ -190,8 +219,11 @@ Valid provider names:
190
219
  ```txt
191
220
  test
192
221
  openai
222
+ openai-codex
193
223
  anthropic
194
224
  openrouter
225
+ opencode
226
+ opencode-go
195
227
  custom
196
228
  ```
197
229
 
@@ -200,8 +232,11 @@ Current provider adapters:
200
232
  ```txt
201
233
  test/fake
202
234
  openai via Pi SDK
235
+ openai-codex via Pi SDK (local ChatGPT OAuth)
203
236
  anthropic via Pi SDK
204
237
  openrouter via Pi SDK
238
+ opencode via Pi SDK
239
+ opencode-go via Pi SDK
205
240
  ```
206
241
 
207
242
  `custom` is a reserved config value. It is not implemented as a local provider adapter yet.
@@ -220,7 +255,9 @@ secrets: [],
220
255
 
221
256
  `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
257
 
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.
258
+ Before claiming real conversation behavior has been tested, ask the owner which provider to use: OpenRouter, OpenAI, Anthropic, OpenCode Zen, OpenCode Go, 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.
259
+
260
+ ChatGPT/Codex subscription login (local only): run `agentkit provider login openai-codex` in an interactive terminal, sign in through the printed URL, and set `provider: { name: "openai-codex", model: "gpt-5.4" }`. No `OPENAI_API_KEY` is required for this provider. Keep secrets needed by tools or other services. The AgentKit session is stored outside capsules in `~/.agentkit/providers/openai-codex.json`, renewed through Pi, and never copied from or into the Codex app cache. `agentkit provider status openai-codex` reports local status without tokens; `agentkit provider logout openai-codex` removes the local session without revoking it at OpenAI. Cloudflare, container, and VPS builds reject this provider with `target_runtime_incompatible`; hosted OAuth is not supported. See `docs/guides/use-provider.md`.
224
261
 
225
262
  OpenAI example:
226
263
 
@@ -243,6 +280,32 @@ npm run chat -- --message "hello"
243
280
 
244
281
  If a provider key is missing, the runtime returns `secret_not_found`.
245
282
 
283
+ For OpenRouter, prefer model ids or aliases known to the installed Pi SDK, such as `~google/gemini-flash-latest`. If an OpenRouter id is newer than Pi's registry, AgentKit passes the raw id through to OpenRouter with conservative unknown-model metadata. OpenRouter can still reject invalid, inaccessible, or unsupported models, and unknown-model cost/capability metadata is not authoritative.
284
+
285
+ OpenCode Zen example:
286
+
287
+ ```ts
288
+ provider: {
289
+ name: "opencode",
290
+ model: "big-pickle",
291
+ },
292
+ secrets: ["OPENCODE_API_KEY"],
293
+ ```
294
+
295
+ Use an OpenCode Zen model id listed by the installed Pi SDK, such as `big-pickle`, `deepseek-v4-flash-free`, `claude-sonnet-4-5`, or `gpt-5.4-mini`.
296
+
297
+ OpenCode Go example:
298
+
299
+ ```ts
300
+ provider: {
301
+ name: "opencode-go",
302
+ model: "deepseek-v4-flash",
303
+ },
304
+ secrets: ["OPENCODE_API_KEY"],
305
+ ```
306
+
307
+ Use an OpenCode Go model id listed by the installed Pi SDK, such as `deepseek-v4-flash`, `deepseek-v4-pro`, `glm-5.1`, `kimi-k2.6`, `minimax-m2.7`, or `qwen3.6-plus`.
308
+
246
309
  ## Knowledge Contract
247
310
 
248
311
  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.
@@ -292,7 +355,7 @@ agentkit knowledge inspect
292
355
  agentkit knowledge search "refund policy" --top-k 3
293
356
  ```
294
357
 
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.
358
+ `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. Local lexical search uses SQLite FTS5 when the local SQLite build provides it; when it does not, AgentKit automatically keeps indexing and searching with a normal SQLite table and simpler text matching. 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
359
 
297
360
  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
361
 
@@ -317,7 +380,7 @@ Channels are hosted inbound/outbound conversation transports. They are separate
317
380
  Use these helpers in `agentkit.config.ts`:
318
381
 
319
382
  ```ts
320
- import { defineAgent, telegramChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
383
+ import { defineAgent, discordChannel, slackChannel, telegramChannel, webhookChannel, webhookOutputChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
321
384
 
322
385
  export default defineAgent({
323
386
  name: "support-agent",
@@ -330,6 +393,12 @@ export default defineAgent({
330
393
  websiteChannel({ name: "website-chat" }),
331
394
  telegramChannel({ name: "support-telegram" }),
332
395
  whatsappChannel({ name: "support-whatsapp", provider: "zapster" }),
396
+ whatsappChannel({ name: "support-uazapi", provider: "uazapi" }),
397
+ discordChannel({ name: "support-discord" }),
398
+ discordChannel({ name: "server-discord", mode: "bot" }),
399
+ slackChannel({ name: "support-slack" }),
400
+ webhookChannel({ name: "n8n-webhook" }),
401
+ webhookOutputChannel({ name: "crm-callback", urlSecret: "CRM_CALLBACK_URL" }),
333
402
  ],
334
403
  access: { mode: "public" },
335
404
  storage: { driver: "agentkit" },
@@ -341,10 +410,13 @@ Rules:
341
410
  - `runtime: "edge"` is required when `channels` are configured.
342
411
  - Channel names are stable lowercase identifiers and must be unique.
343
412
  - Config stores secret names only, never secret values.
413
+ - UAZAPI and Zapster WhatsApp channels require `UAZAPI_WEBHOOK_TOKEN` and `ZAPSTER_WEBHOOK_TOKEN`; webhooks without the matching query token are rejected.
344
414
  - AgentKit owns channel webhook URLs, dedupe, identities, queue state, and delivery logs.
345
415
  - Do not store channel plumbing in the user's Turso database.
346
416
  - Use `buffer.mode: "debounce"` when a channel should coalesce rapid client messages into one agent run.
347
417
  - Buffered deliveries show `buffered`, then flush to one `queued` run after `quietWindowMs`, `maxWaitMs`, `maxMessages`, or `maxChars`.
418
+ - Use `replyTo` when an inbound channel should receive on one transport and answer on another configured channel.
419
+ - Use `webhookOutputChannel` when the reply target is a generic HTTPS callback URL stored in a managed secret.
348
420
 
349
421
  Channel buffer example:
350
422
 
@@ -365,11 +437,14 @@ whatsappChannel({
365
437
  Useful guides:
366
438
 
367
439
  - Add a channel: `docs/guides/add-channel.md`
440
+ - Connect Discord: `docs/guides/connect-discord.md`
441
+ - Connect Slack: `docs/guides/connect-slack.md`
368
442
  - Connect Telegram: `docs/guides/connect-telegram.md`
443
+ - Connect WhatsApp through Evolution API: `docs/guides/connect-whatsapp-evolution.md`
444
+ - Connect WhatsApp through UAZAPI: `docs/guides/connect-whatsapp-uazapi.md`
369
445
  - Connect WhatsApp through Zapster: `docs/guides/connect-whatsapp-zapster.md`
370
446
  - Debug a channel: `docs/guides/debug-channel.md`
371
447
  - Channel security: `docs/guides/channel-security.md`
372
- - Production handoff: `docs/guides/channels-production-handoff.md`
373
448
 
374
449
  Telegram required secrets:
375
450
 
@@ -382,9 +457,110 @@ Zapster WhatsApp required secrets:
382
457
 
383
458
  ```txt
384
459
  ZAPSTER_API_KEY
385
- ZAPSTER_WEBHOOK_SECRET
460
+ ZAPSTER_INSTANCE_ID
461
+ ZAPSTER_WEBHOOK_ID
462
+ ZAPSTER_WEBHOOK_TOKEN
463
+ ```
464
+
465
+ UAZAPI WhatsApp required secrets:
466
+
467
+ ```txt
468
+ UAZAPI_BASE_URL
469
+ UAZAPI_TOKEN
470
+ UAZAPI_WEBHOOK_TOKEN
471
+ ```
472
+
473
+ `UAZAPI_WEBHOOK_TOKEN` and `ZAPSTER_WEBHOOK_TOKEN` are AgentKit-owned secrets generated by the user, not provider-issued credentials. For local `agentkit dev`, expose the printed port through an HTTPS tunnel and register the exact `/channels/<name>/whatsapp/<provider>/webhook?token=<secret>` URL. Only authenticated channel webhook routes accept a tunnel host; other local endpoints remain loopback-only.
474
+
475
+ Evolution API WhatsApp required secrets:
476
+
477
+ ```txt
478
+ EVOLUTION_API_BASE_URL
479
+ EVOLUTION_API_KEY
480
+ EVOLUTION_INSTANCE_NAME
481
+ EVOLUTION_WEBHOOK_TOKEN
482
+ ```
483
+
484
+ Discord slash-command required secret:
485
+
486
+ ```txt
487
+ DISCORD_PUBLIC_KEY
488
+ ```
489
+
490
+ Discord bot-mode required secret:
491
+
492
+ ```txt
493
+ DISCORD_BOT_TOKEN
494
+ ```
495
+
496
+ Generic webhook required secret:
497
+
498
+ ```txt
499
+ AGENTKIT_WEBHOOK_SECRET
500
+ ```
501
+
502
+ Generic webhook payloads should be canonical JSON:
503
+
504
+ ```json
505
+ {
506
+ "event_id": "evt_123",
507
+ "external_id": "customer_123",
508
+ "message": "hello from n8n"
509
+ }
510
+ ```
511
+
512
+ Use `Authorization: Bearer <AGENTKIT_WEBHOOK_SECRET>`, `X-AgentKit-Webhook-Secret`, or `X-AgentKit-Webhook-Signature: sha256=<hmac>` where the HMAC is SHA-256 over the exact raw JSON body. The hosted URL is `/channels/<name>/webhook`.
513
+
514
+ Without `replyTo`, generic webhooks are inbound-only and do not call back into the source system. To receive on one channel and answer on another, add a static `replyTo` route:
515
+
516
+ ```ts
517
+ webhookChannel({
518
+ name: "lead-webhook",
519
+ replyTo: {
520
+ channel: "main-whatsapp",
521
+ recipientFrom: "phone",
522
+ },
523
+ })
524
+
525
+ whatsappChannel({
526
+ name: "main-whatsapp",
527
+ provider: "evolution",
528
+ })
529
+ ```
530
+
531
+ `recipientFrom` is a dotted JSON path such as `phone`, `customer.phone`, or `payload.customer.phone`. It must resolve to a non-empty scalar in the inbound payload. Do not use `recipientFrom` for Discord or Slack replies because those transports need provider-native source identities.
532
+
533
+ Multiple webhooks are multiple named channels:
534
+
535
+ ```ts
536
+ webhookChannel({ name: "n8n-webhook" })
537
+ webhookChannel({ name: "make-webhook" })
538
+ webhookChannel({ name: "crm-webhook", replyTo: { channel: "main-whatsapp", recipientFrom: "phone" } })
386
539
  ```
387
540
 
541
+ Generic output webhook channels send the final agent answer to an HTTPS callback URL:
542
+
543
+ ```ts
544
+ webhookOutputChannel({
545
+ name: "crm-callback",
546
+ urlSecret: "CRM_CALLBACK_URL",
547
+ auth: {
548
+ type: "bearer",
549
+ tokenSecret: "CRM_CALLBACK_TOKEN",
550
+ },
551
+ })
552
+
553
+ webhookChannel({
554
+ name: "n8n-webhook",
555
+ replyTo: {
556
+ channel: "crm-callback",
557
+ recipientFrom: "crm_id",
558
+ },
559
+ })
560
+ ```
561
+
562
+ `CRM_CALLBACK_URL` and output auth values are managed secrets only. The URL must be public HTTPS; AgentKit rejects localhost, private network, link-local, and metadata-service hosts. Supported output auth modes are `none`, `bearer`, `header`, and `hmac`. Generic output channels do not have public inbound webhook URLs, so `agentkit channels test <output-name>` is unsupported.
563
+
388
564
  Common channel verification:
389
565
 
390
566
  ```sh
@@ -392,23 +568,37 @@ agentkit inspect
392
568
  agentkit deploy
393
569
  agentkit channels list
394
570
  agentkit channels add telegram support-telegram
571
+ agentkit channels connect whatsapp main-whatsapp --provider evolution
572
+ agentkit channels connect whatsapp support-whatsapp --provider uazapi
573
+ agentkit channels connect discord support-discord
574
+ agentkit channels connect discord server-discord --mode bot
575
+ agentkit channels connect slack support-slack
576
+ agentkit channels connect webhook n8n-webhook
395
577
  agentkit channels setup support-telegram
396
578
  agentkit channels test support-telegram --message "hello"
579
+ agentkit channels test-audio support-telegram --fixture voice-note
580
+ agentkit transcribe smoke --provider groq
397
581
  agentkit channels deliveries list support-telegram
398
582
  agentkit channels deliveries show <delivery-id>
399
583
  ```
400
584
 
401
- `channels setup` is read-only by default. `channels setup <telegram-name> --apply` calls Telegram `setWebhook` and requires `TELEGRAM_BOT_TOKEN` plus `TELEGRAM_WEBHOOK_SECRET`.
585
+ `channels connect` creates or refreshes the channel resource, validates secrets, runs provider setup when supported, then runs the official synthetic smoke. `channels setup` is read-only by default. `channels setup <telegram-name> --apply` calls Telegram `setWebhook` and requires `TELEGRAM_BOT_TOKEN` plus `TELEGRAM_WEBHOOK_SECRET`. `channels setup <uazapi-whatsapp-name> --apply` calls UAZAPI `/webhook` and requires `UAZAPI_BASE_URL`, `UAZAPI_TOKEN`, and `UAZAPI_WEBHOOK_TOKEN`. `channels setup <evolution-whatsapp-name> --apply` calls Evolution API `/webhook/set/{instance}` and requires `EVOLUTION_API_BASE_URL`, `EVOLUTION_API_KEY`, `EVOLUTION_INSTANCE_NAME`, and `EVOLUTION_WEBHOOK_TOKEN`.
586
+
587
+ Discord slash-command mode validates `X-Signature-Ed25519` and `X-Signature-Timestamp` against `DISCORD_PUBLIC_KEY`, answers signed `PING` requests with `type: 1`, acknowledges slash commands with a deferred response, then sends the final answer as an interaction follow-up. Discord bot mode uses `DISCORD_BOT_TOKEN`, Discord Gateway `MESSAGE_CREATE`, Message Content Intent, and `/channels/<channel_id>/messages` bot replies. Discord channels support buffering but do not support `audio` in V1.
402
588
 
403
589
  Default tests are offline. Real provider smoke tests are opt-in:
404
590
 
405
591
  ```sh
406
592
  AGENTKIT_RUN_TELEGRAM_CHANNEL_TESTS=1 bun test
407
593
  AGENTKIT_RUN_ZAPSTER_CHANNEL_TESTS=1 bun test
594
+ AGENTKIT_RUN_UAZAPI_CHANNEL_TESTS=1 bun test
595
+ AGENTKIT_RUN_EVOLUTION_CHANNEL_TESTS=1 bun test
408
596
  ```
409
597
 
410
598
  Telegram smoke also requires `TELEGRAM_BOT_TOKEN`, `TELEGRAM_WEBHOOK_SECRET`, and `AGENTKIT_TELEGRAM_WEBHOOK_URL`.
411
- Zapster smoke also requires `ZAPSTER_API_KEY`, `AGENTKIT_ZAPSTER_SEND_URL`, and `AGENTKIT_ZAPSTER_TO`.
599
+ Zapster smoke also requires `ZAPSTER_API_KEY`, `ZAPSTER_WEBHOOK_TOKEN`, `AGENTKIT_ZAPSTER_SEND_URL`, and `AGENTKIT_ZAPSTER_TO`.
600
+ UAZAPI smoke also requires `UAZAPI_BASE_URL`, `UAZAPI_TOKEN`, `UAZAPI_WEBHOOK_TOKEN`, and `AGENTKIT_UAZAPI_TO`.
601
+ Evolution smoke also requires `EVOLUTION_API_BASE_URL`, `EVOLUTION_API_KEY`, `EVOLUTION_INSTANCE_NAME`, and `AGENTKIT_EVOLUTION_TO`.
412
602
 
413
603
  ## Tool Contract
414
604
 
@@ -469,9 +659,11 @@ Tool runtime rules:
469
659
  - `timeoutMs` overrides the default;
470
660
  - tool calls are saved in AgentKit-managed local storage;
471
661
  - secret values are redacted before storage.
662
+ - permissions ending in `:read` may run automatically; any other declared permission requires a reviewed direct `agentkit tool` invocation and is blocked from chat, channels, and evals;
472
663
  - tools that need SQL use canonical `ctx.db`; `ctx.database` and `ctx.storage.sql` are supported aliases;
473
664
  - tools can use `ctx.db.batch([...])` for atomic writes; local tools can also use `ctx.db.transaction(async (tx) => ...)`;
474
665
  - tools can inspect `ctx.runtime` with `{ environment, invocation, target, database }`;
666
+ - tools can use `ctx.clock` for the same runtime clock injected into the agent prompt, including `now`, `isoTimestamp`, `timeZone`, `localDate`, `localWeekday`, and `localDateTime`;
475
667
  - tools must not import local database drivers or Node-only APIs. Use AgentKit runtime services instead.
476
668
 
477
669
  ## Database Tools And Dual Storage
@@ -505,7 +697,7 @@ CREATE TABLE IF NOT EXISTS appointments (
505
697
  );
506
698
  ```
507
699
 
508
- `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.
700
+ `schema.sql` is an idempotent bootstrap file. Use `CREATE TABLE IF NOT EXISTS`, `CREATE INDEX IF NOT EXISTS`, and only safe additive `ALTER TABLE` statements. Use ordered `migrations/*.sql` for production-shaped schema evolution; `agentkit db migrate` applies unapplied local migrations before `schema.sql`.
509
701
 
510
702
  Example tool:
511
703
 
@@ -670,6 +862,9 @@ GET /_agentkit
670
862
  POST /v1/chat
671
863
  GET /v1/conversations
672
864
  GET /v1/conversations/:id
865
+ GET /v1/conversations/:id/trace
866
+ POST /channels/<name>/<type>/<provider>/webhook
867
+ POST /channels/<name>/webhook
673
868
  ```
674
869
 
675
870
  Chat request:
@@ -689,6 +884,7 @@ After chat:
689
884
  ```sh
690
885
  agentkit conversations list
691
886
  agentkit conversations show <conversation-id>
887
+ agentkit conversations trace <conversation-id>
692
888
  ```
693
889
 
694
890
  List output columns:
@@ -697,7 +893,7 @@ List output columns:
697
893
  id title updated_at messages
698
894
  ```
699
895
 
700
- Show output includes the conversation id, title, updated timestamp, and each message as `role: content`.
896
+ Show output includes the conversation id, title, updated timestamp, and each message as `role: content`. Trace output includes stored messages and tool calls for the conversation.
701
897
 
702
898
  ## Evals
703
899
 
@@ -716,17 +912,84 @@ npm run eval
716
912
  Supported assertion types:
717
913
 
718
914
  ```txt
719
- contains
720
- not_contains
721
- regex
722
- matches_regex
723
- persisted_tool_call
915
+ response.contains
916
+ response.containsAll
917
+ response.containsAny
918
+ response.caseInsensitiveContains
919
+ response.notContains
920
+ response.regex
921
+ response.matchesRegex
922
+ response.notRegex
923
+ response.maxLength
924
+ tools.called
925
+ tools.calledOnce
926
+ tools.count
927
+ tools.order
928
+ tools.persisted
724
929
  ```
725
930
 
726
- `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.
931
+ Import `defineEval` from `@andreprado/agentkit` when writing new evals. `tools.persisted` validates the tool call saved in the eval run's 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`, `rendered`, `status`, and/or `visibility`. `tool_call` and `persisted_tool_call` remain accepted as backwards-compatible aliases, but new evals should use `tools.persisted`.
932
+
933
+ For date-sensitive evals, set top-level `now` to an ISO timestamp with an explicit timezone designator such as `Z` or `-05:00`. AgentKit uses that fixed clock for every turn and tool call in the eval so "today", "tomorrow", and weekdays remain deterministic while normal chat continues to use the real current date.
727
934
 
728
935
  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.
729
936
 
937
+ ## Improve From Production
938
+
939
+ Use AgentKit Improve when a hosted or local conversation should become a reproducible local fix loop. Hosted AgentKit Cloud exports evidence; the local coding agent edits the Agent Capsule, writes evals, replays, and deploys.
940
+
941
+ Collect hosted evidence from the last deploy:
942
+
943
+ ```sh
944
+ agentkit improve collect --deploy --since 24h
945
+ ```
946
+
947
+ When the CLI is logged in to AgentKit Cloud, hosted collection first exports deploy evidence such as failed channel deliveries, deploy errors, and conversation IDs from the control plane, then reads replayable conversation traces from the deployed runtime. Without Cloud auth, it falls back to deploy-token conversation trace reads.
948
+
949
+ Hosted conversation reads require a deploy access token even when the chat endpoint is public. `agentkit deploy` normally writes `.agentkit/chat-access-token.json`; use `agentkit access token create agentkit-chat-ui --out .agentkit/chat-access-token.json` to refresh it.
950
+
951
+ Collect one hosted conversation:
952
+
953
+ ```sh
954
+ agentkit improve collect --deploy --conversation-id <conversation-id>
955
+ ```
956
+
957
+ Collect local evidence:
958
+
959
+ ```sh
960
+ agentkit improve collect --since 7d
961
+ ```
962
+
963
+ The command writes ignored local state:
964
+
965
+ ```txt
966
+ .agentkit/improve/<run>/
967
+ bundle.json
968
+ report.json
969
+ traces/
970
+ ```
971
+
972
+ Generate committed regression evals:
973
+
974
+ ```sh
975
+ agentkit improve evals .agentkit/improve/<run>
976
+ ```
977
+
978
+ Then replay before deploying:
979
+
980
+ ```sh
981
+ agentkit replay .agentkit/improve/<run> --against local
982
+ npm run eval
983
+ agentkit deploy --smoke "hello"
984
+ ```
985
+
986
+ Replay runs collected user turns through the local capsule with `ctx.runtime.environment === "eval"` and `ctx.runtime.invocation === "eval"`. Generated evals live under `evals/regressions/`; review them before committing, especially when traces contain real client details or overly strict prose assertions.
987
+
988
+ Full guides:
989
+
990
+ - `docs/guides/improve-from-production.md`
991
+ - `docs/guides/replay-production-traces.md`
992
+
730
993
  ## Security Rules
731
994
 
732
995
  Never commit:
@@ -750,9 +1013,10 @@ prompts/
750
1013
  docs/
751
1014
  ```
752
1015
 
753
- 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.
1016
+ Local `.env` is development only. Use `.env.schema` as the committed secret-name contract; local AgentKit commands load `.env` directly. Hosted deploys require an AgentKit Cloud account with `cloudflare_deploy_alpha` or purchased/manual deploy slots. First-time paid access uses `agentkit billing checkout --slots <count>` and `agentkit billing claim billint_... --secret bsec_...`; existing accounts use `agentkit login --token ...`. Hosted secrets use `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.
754
1017
 
755
1018
  Tools are a security boundary. A tool must declare every secret it needs. The runtime injects only tool-declared secrets.
1019
+ Agent Capsules are trusted executable TypeScript, not sandboxed configuration. Run AgentKit commands only in Capsules whose config, tools, evals, and sync modules you trust.
756
1020
 
757
1021
  ## Hosted Deploy Contract
758
1022
 
@@ -762,7 +1026,10 @@ Current flow:
762
1026
 
763
1027
  ```sh
764
1028
  agentkit deploy --dry-run
1029
+ agentkit billing checkout --slots 1 --email user@example.com
1030
+ agentkit billing claim billint_... --secret bsec_...
765
1031
  agentkit login --token agk_user_...
1032
+ agentkit account token create new-laptop --use
766
1033
  agentkit deploy doctor
767
1034
  agentkit deploy --smoke "hello"
768
1035
  agentkit deploy status
@@ -770,9 +1037,9 @@ agentkit deploy smoke --message "hello"
770
1037
  agentkit chat-ui --deploy
771
1038
  ```
772
1039
 
773
- `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.
1040
+ `agentkit deploy doctor` checks AgentKit Cloud login, hosted deploy entitlement, online deploy capacity, hosted secrets, local `.env` names that still need `agentkit secret set`, managed Composio API/auth-config readiness by toolkit, and private-access runtime token handling. `agentkit deploy` sends the capsule to AgentKit Cloud, runs the same readiness check automatically before building and uploading, updates the current project deploy slot by default, writes the local chat/UI deploy access token to `.agentkit/chat-access-token.json`, and prints a production handoff with URL, UI command, secret status, database/schema artifact, integration connect commands, smoke status, and the next recommended command. `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, shows the conversation id and tool calls, and supports starting a new conversation. Use `agentkit conversations trace <conversation-id> --deploy` to pull hosted conversation messages and tool calls from the last deploy. Production deploys require an account with `cloudflare_deploy_alpha` or purchased/manual deploy slots; local commands and dry-run builds do not require login. AgentKit owns infrastructure selection, backend migration, managed secrets, and public URL creation.
774
1041
 
775
- 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.
1042
+ 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 when the owner gives you a non-default AgentKit Cloud API URL.
776
1043
 
777
1044
  Account/access flow:
778
1045
 
@@ -780,6 +1047,9 @@ Account/access flow:
780
1047
  agentkit secret set OPENAI_API_KEY --from-local-env
781
1048
  agentkit secret sync --from-local
782
1049
  agentkit secret list
1050
+ agentkit account token list
1051
+ agentkit skills status
1052
+ agentkit skills sync
783
1053
  agentkit access token create website-chat --out .agentkit/website-chat-access-token.json
784
1054
  agentkit access token list
785
1055
  ```