@andreprado/agentkit 0.1.0-alpha.2 → 0.1.0-alpha.20

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 (135) hide show
  1. package/README.md +67 -6
  2. package/docs/guides/add-channel.md +118 -7
  3. package/docs/guides/add-knowledge.md +144 -0
  4. package/docs/guides/add-managed-composio.md +163 -0
  5. package/docs/guides/add-tool.md +1 -1
  6. package/docs/guides/channel-security.md +97 -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 +78 -1
  10. package/docs/guides/connect-whatsapp-zapster.md +112 -8
  11. package/docs/guides/create-agent.md +45 -4
  12. package/docs/guides/debug-channel.md +147 -0
  13. package/docs/guides/improve-from-production.md +151 -0
  14. package/docs/guides/prepare-deploy.md +47 -17
  15. package/docs/guides/replay-production-traces.md +72 -0
  16. package/docs/guides/run-evals.md +147 -20
  17. package/docs/guides/security-rules.md +7 -6
  18. package/docs/guides/send-feedback.md +135 -0
  19. package/docs/guides/use-provider.md +27 -3
  20. package/docs/llms-full.txt +303 -55
  21. package/docs/llms.txt +57 -7
  22. package/package.json +2 -5
  23. package/src/cli/args.ts +57 -0
  24. package/src/cli/cloud-client.ts +377 -0
  25. package/src/cli/commands/channels.ts +1315 -0
  26. package/src/cli/commands/feedback.ts +438 -0
  27. package/src/cli/commands/knowledge.ts +136 -0
  28. package/src/cli/commands/transcribe.ts +171 -0
  29. package/src/cli/constants.ts +4 -0
  30. package/src/cli/deploy-chat-ui.ts +535 -0
  31. package/src/cli/deploy-readiness.ts +481 -0
  32. package/src/cli/flags.ts +162 -0
  33. package/src/cli/help.ts +236 -0
  34. package/src/cli/index.ts +1167 -1005
  35. package/src/cli/process.ts +31 -0
  36. package/src/cloud/artifact.ts +139 -0
  37. package/src/cloud/client.ts +80 -0
  38. package/src/cloud/contracts.ts +63 -0
  39. package/src/cloud/index.ts +3 -0
  40. package/src/create-project.ts +21 -6
  41. package/src/index.ts +479 -7
  42. package/src/providers/pi.ts +70 -16
  43. package/src/providers/test.ts +88 -1
  44. package/src/providers/types.ts +7 -0
  45. package/src/runtime/channel-buffer.ts +30 -0
  46. package/src/runtime/channel-test-harness.ts +8 -1
  47. package/src/runtime/channels/discord.ts +896 -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-meta.ts +9 -0
  51. package/src/runtime/channels/whatsapp-zapster.ts +677 -40
  52. package/src/runtime/channels.ts +86 -3
  53. package/src/runtime/chat.ts +130 -38
  54. package/src/runtime/config.ts +483 -18
  55. package/src/runtime/core/manifest.ts +103 -5
  56. package/src/runtime/core/targets.ts +5 -5
  57. package/src/runtime/database.ts +93 -2
  58. package/src/runtime/db-commands.ts +9 -0
  59. package/src/runtime/deploy-readiness.ts +46 -4
  60. package/src/runtime/deploy.ts +1 -1
  61. package/src/runtime/dev-server.ts +759 -41
  62. package/src/runtime/env.ts +8 -3
  63. package/src/runtime/evals.ts +589 -43
  64. package/src/runtime/improve.ts +868 -0
  65. package/src/runtime/inspect.ts +194 -4
  66. package/src/runtime/integrations/composio.ts +423 -0
  67. package/src/runtime/knowledge/chunk.ts +333 -0
  68. package/src/runtime/knowledge/config.ts +135 -0
  69. package/src/runtime/knowledge/embeddings.ts +133 -0
  70. package/src/runtime/knowledge/ingest.ts +521 -0
  71. package/src/runtime/knowledge/prompt-policy.ts +30 -0
  72. package/src/runtime/knowledge/retrieve.ts +303 -0
  73. package/src/runtime/knowledge/schema.ts +100 -0
  74. package/src/runtime/knowledge/tool.ts +64 -0
  75. package/src/runtime/knowledge/vector.ts +258 -0
  76. package/src/runtime/prompt-context.ts +141 -0
  77. package/src/runtime/runtime-contract.ts +86 -8
  78. package/src/runtime/skills.ts +95 -0
  79. package/src/runtime/spec.ts +152 -0
  80. package/src/runtime/sync.ts +144 -0
  81. package/src/runtime/targets/cloudflare/build.ts +1430 -185
  82. package/src/runtime/targets/container/server.ts +1 -1
  83. package/src/runtime/targets/vps/deploy.ts +26 -9
  84. package/src/runtime/tool-runner.ts +9 -1
  85. package/src/runtime/tools.ts +128 -2
  86. package/src/runtime/traces.ts +41 -0
  87. package/src/runtime/transcription.ts +483 -0
  88. package/src/storage/sqlite.ts +149 -3
  89. package/src/templates/blank.ts +76 -17
  90. package/src/templates/dentista.ts +1011 -0
  91. package/src/templates/index.ts +2 -0
  92. package/src/templates/skills/agentkit-build-agent/SKILL.md +52 -0
  93. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +21 -0
  94. package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
  95. package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
  96. package/src/templates/skills/agentkit-capsule/SKILL.md +70 -0
  97. package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
  98. package/src/templates/skills/agentkit-channels/SKILL.md +104 -0
  99. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +65 -0
  100. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +66 -0
  101. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  102. package/src/templates/skills/agentkit-channels/references/slack.md +56 -0
  103. package/src/templates/skills/agentkit-channels/references/telegram.md +72 -0
  104. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +77 -0
  105. package/src/templates/skills/agentkit-database/SKILL.md +45 -0
  106. package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
  107. package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
  108. package/src/templates/skills/agentkit-deploy/SKILL.md +50 -0
  109. package/src/templates/skills/agentkit-evals/SKILL.md +109 -0
  110. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +29 -0
  111. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +18 -0
  112. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +18 -0
  113. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +27 -0
  114. package/src/templates/skills/agentkit-improve/SKILL.md +86 -0
  115. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  116. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  117. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  118. package/src/templates/skills/agentkit-integrations/SKILL.md +76 -0
  119. package/src/templates/skills/agentkit-knowledge/SKILL.md +43 -0
  120. package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
  121. package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
  122. package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
  123. package/src/templates/skills/agentkit-prompts/SKILL.md +47 -0
  124. package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
  125. package/src/templates/skills/agentkit-provider/SKILL.md +60 -0
  126. package/src/templates/skills/agentkit-security/SKILL.md +56 -0
  127. package/src/templates/skills/agentkit-tools/SKILL.md +37 -0
  128. package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
  129. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
  130. package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
  131. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +76 -0
  132. package/src/templates/support.ts +77 -18
  133. package/docs/guides/channels-production-handoff.md +0 -99
  134. package/docs/portable-deploy-release-checklist.md +0 -41
  135. package/src/runtime/targets/cloudflare/deploy.ts +0 -5475
@@ -30,59 +30,96 @@ The capsule root is the runtime boundary. Run AgentKit commands from the directo
30
30
 
31
31
  ## Current Command Surface
32
32
 
33
- Implemented local commands:
33
+ Current commands:
34
34
 
35
35
  ```sh
36
- agentkit new <name> --template blank
37
- agentkit new <name> --template support
38
- agentkit chat --message "hello"
39
- agentkit tool <name> --input <path-or-json>
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>]
40
51
  agentkit eval run
52
+ agentkit eval from-conversation <conversation-id> [--out <path>] [--force]
53
+ agentkit improve collect [--deploy] [--since <duration|iso>] [--conversation-id <id>] [--out <directory>]
54
+ agentkit improve evals <bundle-dir-or-json> [--force]
55
+ agentkit replay <bundle-dir-or-json> --against local
56
+ 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>]
57
+ agentkit feedback preview [draft.json]
58
+ agentkit feedback send [draft.json] [--about last-run|deploy|manual] [--kind <kind>] --summary <text> [--message <text>] [--api <url>] [--save]
41
59
  agentkit conversations list
42
60
  agentkit conversations show <conversation-id>
61
+ agentkit conversations trace <conversation-id> [--deploy]
43
62
  agentkit channels list
44
- agentkit channels add website website-chat
45
- agentkit channels add telegram support-telegram
46
- agentkit channels add whatsapp support-whatsapp --provider zapster
47
- agentkit channels setup <name>
48
- agentkit channels setup <name> --apply
49
- agentkit channels status <name>
50
- agentkit channels test <name> --message "hello"
51
- agentkit channels test <name> --fixture ./fixtures/provider-event.json
52
- agentkit channels deliveries list <name>
53
- agentkit channels deliveries show <delivery-id>
63
+ agentkit channels add <website|telegram|whatsapp|discord|slack> <name> [--provider zapster|meta] [--mode interactions|bot] [--api <url>]
64
+ agentkit channels connect <website|telegram|whatsapp|discord|slack> <name> [--provider zapster|meta] [--mode interactions|bot] [--api <url>]
65
+ agentkit channels setup <name> [--apply] [--api <url>]
66
+ agentkit channels status <name> [--api <url>]
67
+ agentkit channels test <name> [--message <text>] [--fixture <path>] [--api <url>]
68
+ agentkit channels test-audio <name> [--fixture voice-note|audio-file|<path>] [--api <url>]
69
+ agentkit channels deliveries list <name> [--api <url>]
70
+ agentkit channels deliveries show <delivery-id> [--api <url>]
71
+ agentkit integrations status [--toolkit <slug>] [--api <url>]
72
+ agentkit integrations connect composio [--toolkit <slug>] [--callback-url <url>] [--api <url>]
73
+ agentkit skills status
74
+ agentkit skills sync
54
75
  agentkit inspect
55
- agentkit env set <NAME> <VALUE>
56
- agentkit env list
57
- agentkit env unset <NAME>
58
- agentkit docs path
59
- agentkit docs llms
60
- agentkit docs full
61
- agentkit handoff codex [goal]
62
- agentkit handoff claude [goal]
63
- agentkit dev
64
- agentkit dev --port 4124
65
- agentkit build
66
- agentkit deploy
67
- agentkit deploy --dry-run
76
+ agentkit build [--target cloudflare|container]
77
+ agentkit billing checkout --slots <count> [--email <email>] [--api <url>]
78
+ agentkit billing status <billing-intent-id> --secret <secret> [--api <url>]
79
+ agentkit billing claim <billing-intent-id> --secret <secret> [--token-name <name>] [--api <url>]
80
+ agentkit billing portal [--api <url>]
68
81
  agentkit login --token <token>
69
82
  agentkit logout
83
+ agentkit account token create <name> [--api <url>] [--use] [--out <path>]
84
+ agentkit account token list [--api <url>]
85
+ agentkit account token revoke <token-id> [--api <url>]
86
+ agentkit deploy [--target cloudflare|vps] [--host <host>] [--api <url>] [--dry-run] [--anonymous] [--local-wrangler] [--smoke <message>]
87
+ agentkit deploy doctor [--api <url>] [--anonymous]
88
+ agentkit deploy smoke [--message <text>] [--api <url>]
70
89
  agentkit deploy status
71
90
  agentkit deploy pause
72
91
  agentkit deploy resume
92
+ agentkit transcribe smoke [--provider test|openai|groq] [--model <model>] [--fixture <audio-file>]
73
93
  agentkit secret set <NAME> <VALUE>
94
+ agentkit secret set <NAME> --stdin
95
+ agentkit secret set <NAME> --from-env [ENV_NAME]
96
+ agentkit secret set <NAME> --from-local-env
97
+ agentkit secret sync --from-local
74
98
  agentkit secret list
75
99
  agentkit secret unset <NAME>
76
- agentkit access token create <name>
100
+ agentkit access token create <name> [--api <url>] [--out <path>]
77
101
  agentkit access token list
78
102
  agentkit access token revoke <token-id>
103
+ agentkit env set <NAME> <VALUE>
104
+ agentkit env set <NAME> --stdin
105
+ agentkit env set <NAME> --from-env [ENV_NAME]
106
+ agentkit env list
107
+ agentkit env unset <NAME>
108
+ agentkit docs path
109
+ agentkit docs llms
110
+ agentkit docs full
111
+ agentkit handoff codex [goal]
112
+ agentkit handoff claude [goal]
113
+ agentkit help commands
79
114
  ```
80
115
 
81
- Planned commands described by the contract but not implemented yet:
116
+ 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.
82
117
 
83
- ```sh
84
- agentkit eval create-from-conversation <conversation-id>
85
- ```
118
+ 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.
119
+
120
+ 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`.
121
+
122
+ 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. Managed external write actions require tool input `confirmed: true` by default unless the integration sets `confirmExternalWrites: false`. See `docs/guides/add-managed-composio.md`.
86
123
 
87
124
  ## Create And Test A Capsule
88
125
 
@@ -95,7 +132,6 @@ cd /tmp/agentkit-demo
95
132
 
96
133
  npx @andreprado/agentkit@alpha new demo --template blank
97
134
  cd demo
98
- npm install
99
135
  npm run chat -- --message "hello"
100
136
  npm run chat -- --message "second message"
101
137
  npm run eval
@@ -117,7 +153,6 @@ The primary flow is:
117
153
  ```sh
118
154
  agentkit new eye-office-agent --template blank
119
155
  cd eye-office-agent
120
- npm install
121
156
  ```
122
157
 
123
158
  Then open the folder in Codex, Claude Code, or another coding agent and ask directly:
@@ -126,7 +161,7 @@ Then open the folder in Codex, Claude Code, or another coding agent and ask dire
126
161
  Develop an appointment and intake agent for an ophthalmology office.
127
162
  ```
128
163
 
129
- The coding agent should infer the first useful version, edit `prompts/instructions.md`, `agentkit.config.ts`, and `tools/`, then run the verification commands before finishing.
164
+ 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.
130
165
 
131
166
  Optional handoff shortcut:
132
167
 
@@ -135,7 +170,9 @@ npm run agentkit -- handoff codex "Develop an appointment and intake agent for a
135
170
  npm run agentkit -- handoff claude "Develop an appointment and intake agent for an ophthalmology office."
136
171
  ```
137
172
 
138
- The command prints a ready-to-paste prompt that points the coding agent at `AGENTKIT.md` and the packaged `llms-full.txt` contract.
173
+ 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.
174
+
175
+ 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.
139
176
 
140
177
  ## Agent Config
141
178
 
@@ -151,6 +188,7 @@ export default defineAgent({
151
188
  name: "test",
152
189
  model: "fake",
153
190
  },
191
+ timeZone: "America/New_York",
154
192
  instructions: "./prompts/instructions.md",
155
193
  secrets: [],
156
194
  tools: [],
@@ -163,6 +201,8 @@ export default defineAgent({
163
201
  });
164
202
  ```
165
203
 
204
+ `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.
205
+
166
206
  Valid runtime values:
167
207
 
168
208
  ```txt
@@ -203,7 +243,11 @@ provider: {
203
243
  secrets: [],
204
244
  ```
205
245
 
206
- Use OpenAI locally:
246
+ `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.
247
+
248
+ 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.
249
+
250
+ OpenAI example:
207
251
 
208
252
  ```ts
209
253
  provider: {
@@ -224,6 +268,75 @@ npm run chat -- --message "hello"
224
268
 
225
269
  If a provider key is missing, the runtime returns `secret_not_found`.
226
270
 
271
+ 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.
272
+
273
+ ## Knowledge Contract
274
+
275
+ 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.
276
+
277
+ Configure Knowledge in `agentkit.config.ts`:
278
+
279
+ ```ts
280
+ knowledge: {
281
+ sources: [
282
+ "knowledge/faq.md",
283
+ { path: "knowledge/prices.csv", title: "Prices" },
284
+ ],
285
+ retrieval: {
286
+ topK: 8,
287
+ hybrid: false,
288
+ },
289
+ },
290
+ ```
291
+
292
+ 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.
293
+
294
+ 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:
295
+
296
+ ```ts
297
+ knowledge: {
298
+ sources: ["knowledge/faq.md"],
299
+ embedding: {
300
+ provider: "openai",
301
+ model: "text-embedding-3-small",
302
+ secret: "KNOWLEDGE_OPENAI_API_KEY",
303
+ },
304
+ retrieval: {
305
+ topK: 8,
306
+ hybrid: true,
307
+ },
308
+ },
309
+ ```
310
+
311
+ Set the local embedding secret with `agentkit env set KNOWLEDGE_OPENAI_API_KEY --stdin`. Do not commit the value.
312
+
313
+ Knowledge commands:
314
+
315
+ ```sh
316
+ agentkit knowledge add knowledge/faq.md
317
+ agentkit knowledge sync
318
+ agentkit knowledge inspect
319
+ agentkit knowledge search "refund policy" --top-k 3
320
+ ```
321
+
322
+ `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.
323
+
324
+ 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:
325
+
326
+ ```sh
327
+ agentkit chat --message '{"tool":"agentkit_search_knowledge","input":{"query":"refund policy","topK":1}}'
328
+ ```
329
+
330
+ Expected output:
331
+
332
+ ```txt
333
+ Tool agentkit_search_knowledge: completed
334
+ ```
335
+
336
+ 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.
337
+
338
+ Full guide: `docs/guides/add-knowledge.md`.
339
+
227
340
  ## Channel Contract
228
341
 
229
342
  Channels are hosted inbound/outbound conversation transports. They are separate from tools: channels receive user messages, while tools let the agent call external systems.
@@ -231,7 +344,7 @@ Channels are hosted inbound/outbound conversation transports. They are separate
231
344
  Use these helpers in `agentkit.config.ts`:
232
345
 
233
346
  ```ts
234
- import { defineAgent, telegramChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
347
+ import { defineAgent, discordChannel, slackChannel, telegramChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
235
348
 
236
349
  export default defineAgent({
237
350
  name: "support-agent",
@@ -244,6 +357,9 @@ export default defineAgent({
244
357
  websiteChannel({ name: "website-chat" }),
245
358
  telegramChannel({ name: "support-telegram" }),
246
359
  whatsappChannel({ name: "support-whatsapp", provider: "zapster" }),
360
+ discordChannel({ name: "support-discord" }),
361
+ discordChannel({ name: "server-discord", mode: "bot" }),
362
+ slackChannel({ name: "support-slack" }),
247
363
  ],
248
364
  access: { mode: "public" },
249
365
  storage: { driver: "agentkit" },
@@ -257,15 +373,34 @@ Rules:
257
373
  - Config stores secret names only, never secret values.
258
374
  - AgentKit owns channel webhook URLs, dedupe, identities, queue state, and delivery logs.
259
375
  - Do not store channel plumbing in the user's Turso database.
376
+ - Use `buffer.mode: "debounce"` when a channel should coalesce rapid client messages into one agent run.
377
+ - Buffered deliveries show `buffered`, then flush to one `queued` run after `quietWindowMs`, `maxWaitMs`, `maxMessages`, or `maxChars`.
378
+
379
+ Channel buffer example:
380
+
381
+ ```ts
382
+ whatsappChannel({
383
+ name: "support-whatsapp",
384
+ provider: "zapster",
385
+ buffer: {
386
+ mode: "debounce",
387
+ quietWindowMs: 2500,
388
+ maxWaitMs: 12000,
389
+ maxMessages: 20,
390
+ maxChars: 8000,
391
+ },
392
+ })
393
+ ```
260
394
 
261
395
  Useful guides:
262
396
 
263
397
  - Add a channel: `docs/guides/add-channel.md`
398
+ - Connect Discord: `docs/guides/connect-discord.md`
399
+ - Connect Slack: `docs/guides/connect-slack.md`
264
400
  - Connect Telegram: `docs/guides/connect-telegram.md`
265
401
  - Connect WhatsApp through Zapster: `docs/guides/connect-whatsapp-zapster.md`
266
402
  - Debug a channel: `docs/guides/debug-channel.md`
267
403
  - Channel security: `docs/guides/channel-security.md`
268
- - Production handoff: `docs/guides/channels-production-handoff.md`
269
404
 
270
405
  Telegram required secrets:
271
406
 
@@ -278,7 +413,20 @@ Zapster WhatsApp required secrets:
278
413
 
279
414
  ```txt
280
415
  ZAPSTER_API_KEY
281
- ZAPSTER_WEBHOOK_SECRET
416
+ ZAPSTER_INSTANCE_ID
417
+ ZAPSTER_WEBHOOK_ID
418
+ ```
419
+
420
+ Discord slash-command required secret:
421
+
422
+ ```txt
423
+ DISCORD_PUBLIC_KEY
424
+ ```
425
+
426
+ Discord bot-mode required secret:
427
+
428
+ ```txt
429
+ DISCORD_BOT_TOKEN
282
430
  ```
283
431
 
284
432
  Common channel verification:
@@ -288,13 +436,20 @@ agentkit inspect
288
436
  agentkit deploy
289
437
  agentkit channels list
290
438
  agentkit channels add telegram support-telegram
439
+ agentkit channels connect discord support-discord
440
+ agentkit channels connect discord server-discord --mode bot
441
+ agentkit channels connect slack support-slack
291
442
  agentkit channels setup support-telegram
292
443
  agentkit channels test support-telegram --message "hello"
444
+ agentkit channels test-audio support-telegram --fixture voice-note
445
+ agentkit transcribe smoke --provider groq
293
446
  agentkit channels deliveries list support-telegram
294
447
  agentkit channels deliveries show <delivery-id>
295
448
  ```
296
449
 
297
- `channels setup` is read-only by default. `channels setup <telegram-name> --apply` calls Telegram `setWebhook` and requires `TELEGRAM_BOT_TOKEN` plus `TELEGRAM_WEBHOOK_SECRET`.
450
+ `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`.
451
+
452
+ 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.
298
453
 
299
454
  Default tests are offline. Real provider smoke tests are opt-in:
300
455
 
@@ -368,6 +523,7 @@ Tool runtime rules:
368
523
  - tools that need SQL use canonical `ctx.db`; `ctx.database` and `ctx.storage.sql` are supported aliases;
369
524
  - tools can use `ctx.db.batch([...])` for atomic writes; local tools can also use `ctx.db.transaction(async (tx) => ...)`;
370
525
  - tools can inspect `ctx.runtime` with `{ environment, invocation, target, database }`;
526
+ - tools can use `ctx.clock` for the same runtime clock injected into the agent prompt, including `now`, `isoTimestamp`, `timeZone`, `localDate`, `localWeekday`, and `localDateTime`;
371
527
  - tools must not import local database drivers or Node-only APIs. Use AgentKit runtime services instead.
372
528
 
373
529
  ## Database Tools And Dual Storage
@@ -540,6 +696,8 @@ Run:
540
696
  agentkit dev
541
697
  ```
542
698
 
699
+ 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.
700
+
543
701
  Expected output:
544
702
 
545
703
  ```txt
@@ -551,6 +709,12 @@ Inspect: http://localhost:4123/_agentkit
551
709
  Storage: .agentkit/agentkit.db
552
710
  ```
553
711
 
712
+ To reopen the local UI for the current capsule after the server is already running:
713
+
714
+ ```sh
715
+ agentkit open
716
+ ```
717
+
554
718
  Endpoints:
555
719
 
556
720
  ```txt
@@ -558,6 +722,7 @@ GET /_agentkit
558
722
  POST /v1/chat
559
723
  GET /v1/conversations
560
724
  GET /v1/conversations/:id
725
+ GET /v1/conversations/:id/trace
561
726
  ```
562
727
 
563
728
  Chat request:
@@ -568,6 +733,8 @@ curl -X POST http://localhost:4123/v1/chat \
568
733
  -d '{"message":{"role":"user","content":"hello"}}'
569
734
  ```
570
735
 
736
+ 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.
737
+
571
738
  ## Conversations
572
739
 
573
740
  After chat:
@@ -575,6 +742,7 @@ After chat:
575
742
  ```sh
576
743
  agentkit conversations list
577
744
  agentkit conversations show <conversation-id>
745
+ agentkit conversations trace <conversation-id>
578
746
  ```
579
747
 
580
748
  List output columns:
@@ -583,7 +751,7 @@ List output columns:
583
751
  id title updated_at messages
584
752
  ```
585
753
 
586
- Show output includes the conversation id, title, updated timestamp, and each message as `role: content`.
754
+ 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.
587
755
 
588
756
  ## Evals
589
757
 
@@ -602,14 +770,83 @@ npm run eval
602
770
  Supported assertion types:
603
771
 
604
772
  ```txt
605
- contains
606
- not_contains
607
- regex
608
- matches_regex
609
- persisted_tool_call
773
+ response.contains
774
+ response.containsAll
775
+ response.containsAny
776
+ response.caseInsensitiveContains
777
+ response.notContains
778
+ response.regex
779
+ response.matchesRegex
780
+ response.notRegex
781
+ response.maxLength
782
+ tools.called
783
+ tools.calledOnce
784
+ tools.count
785
+ tools.order
786
+ tools.persisted
610
787
  ```
611
788
 
612
- `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.
789
+ Import `defineEval` from `@andreprado/agentkit` when writing new evals. `tools.persisted` 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`, `rendered`, `status`, and/or `visibility`. `tool_call` and `persisted_tool_call` remain accepted as backwards-compatible aliases, but new evals should use `tools.persisted`.
790
+
791
+ 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.
792
+
793
+ 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.
794
+
795
+ ## Improve From Production
796
+
797
+ 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.
798
+
799
+ Collect hosted evidence from the last deploy:
800
+
801
+ ```sh
802
+ agentkit improve collect --deploy --since 24h
803
+ ```
804
+
805
+ 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.
806
+
807
+ 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.
808
+
809
+ Collect one hosted conversation:
810
+
811
+ ```sh
812
+ agentkit improve collect --deploy --conversation-id <conversation-id>
813
+ ```
814
+
815
+ Collect local evidence:
816
+
817
+ ```sh
818
+ agentkit improve collect --since 7d
819
+ ```
820
+
821
+ The command writes ignored local state:
822
+
823
+ ```txt
824
+ .agentkit/improve/<run>/
825
+ bundle.json
826
+ report.json
827
+ traces/
828
+ ```
829
+
830
+ Generate committed regression evals:
831
+
832
+ ```sh
833
+ agentkit improve evals .agentkit/improve/<run>
834
+ ```
835
+
836
+ Then replay before deploying:
837
+
838
+ ```sh
839
+ agentkit replay .agentkit/improve/<run> --against local
840
+ npm run eval
841
+ agentkit deploy --smoke "hello"
842
+ ```
843
+
844
+ 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.
845
+
846
+ Full guides:
847
+
848
+ - `docs/guides/improve-from-production.md`
849
+ - `docs/guides/replay-production-traces.md`
613
850
 
614
851
  ## Security Rules
615
852
 
@@ -634,7 +871,7 @@ prompts/
634
871
  docs/
635
872
  ```
636
873
 
637
- 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`.
874
+ 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.
638
875
 
639
876
  Tools are a security boundary. A tool must declare every secret it needs. The runtime injects only tool-declared secrets.
640
877
 
@@ -646,22 +883,31 @@ Current flow:
646
883
 
647
884
  ```sh
648
885
  agentkit deploy --dry-run
886
+ agentkit billing checkout --slots 1 --email user@example.com
887
+ agentkit billing claim billint_... --secret bsec_...
649
888
  agentkit login --token agk_user_...
889
+ agentkit account token create new-laptop --use
650
890
  agentkit deploy doctor
651
- agentkit deploy
891
+ agentkit deploy --smoke "hello"
652
892
  agentkit deploy status
893
+ agentkit deploy smoke --message "hello"
894
+ agentkit chat-ui --deploy
653
895
  ```
654
896
 
655
- `agentkit deploy doctor` checks AgentKit Cloud login, `cloudflare_deploy_alpha`, 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 and runs the same readiness check automatically before building and uploading. 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.
897
+ `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, and writes the local chat/UI deploy access token to `.agentkit/chat-access-token.json` for 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, 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.
656
898
 
657
- 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.
899
+ 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.
658
900
 
659
901
  Account/access flow:
660
902
 
661
903
  ```sh
662
- agentkit secret set OPENAI_API_KEY
904
+ agentkit secret set OPENAI_API_KEY --from-local-env
905
+ agentkit secret sync --from-local
663
906
  agentkit secret list
664
- agentkit access token create website-chat
907
+ agentkit account token list
908
+ agentkit skills status
909
+ agentkit skills sync
910
+ agentkit access token create website-chat --out .agentkit/website-chat-access-token.json
665
911
  agentkit access token list
666
912
  ```
667
913
 
@@ -710,6 +956,8 @@ npm install
710
956
  npm run typecheck
711
957
  ```
712
958
 
959
+ `agentkit new` installs dependencies by default. Run this if the scaffold used `--no-install`, the install failed, or `node_modules` was deleted.
960
+
713
961
  Make sure `tsconfig.json` contains:
714
962
 
715
963
  ```json