@andreprado/agentkit 0.1.0-alpha.18 → 0.1.0-alpha.19

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 (56) hide show
  1. package/README.md +3 -0
  2. package/docs/guides/add-channel.md +12 -6
  3. package/docs/guides/add-knowledge.md +10 -0
  4. package/docs/guides/add-managed-composio.md +4 -2
  5. package/docs/guides/channel-security.md +26 -2
  6. package/docs/guides/connect-discord.md +178 -0
  7. package/docs/guides/create-agent.md +13 -0
  8. package/docs/guides/debug-channel.md +8 -2
  9. package/docs/guides/improve-from-production.md +151 -0
  10. package/docs/guides/prepare-deploy.md +29 -8
  11. package/docs/guides/replay-production-traces.md +72 -0
  12. package/docs/guides/run-evals.md +18 -0
  13. package/docs/guides/security-rules.md +5 -5
  14. package/docs/guides/use-provider.md +11 -1
  15. package/docs/llms-full.txt +100 -11
  16. package/docs/llms.txt +17 -1
  17. package/package.json +1 -1
  18. package/src/cli/args.ts +23 -2
  19. package/src/cli/cloud-client.ts +63 -0
  20. package/src/cli/commands/channels.ts +139 -14
  21. package/src/cli/deploy-readiness.ts +5 -2
  22. package/src/cli/help.ts +26 -2
  23. package/src/cli/index.ts +382 -17
  24. package/src/create-project.ts +13 -2
  25. package/src/index.ts +42 -3
  26. package/src/providers/pi.ts +49 -15
  27. package/src/runtime/channel-test-harness.ts +4 -1
  28. package/src/runtime/channels/discord.ts +887 -0
  29. package/src/runtime/channels.ts +15 -0
  30. package/src/runtime/config.ts +35 -3
  31. package/src/runtime/dev-server.ts +149 -8
  32. package/src/runtime/evals.ts +27 -6
  33. package/src/runtime/improve.ts +868 -0
  34. package/src/runtime/knowledge/retrieve.ts +25 -5
  35. package/src/runtime/knowledge/schema.ts +45 -1
  36. package/src/runtime/runtime-contract.ts +54 -0
  37. package/src/runtime/targets/cloudflare/build.ts +248 -193
  38. package/src/runtime/targets/vps/deploy.ts +1 -1
  39. package/src/storage/sqlite.ts +7 -2
  40. package/src/templates/skills/agentkit-capsule/SKILL.md +8 -1
  41. package/src/templates/skills/agentkit-capsule/references/docs-router.md +1 -2
  42. package/src/templates/skills/agentkit-channels/SKILL.md +6 -1
  43. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +2 -1
  44. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  45. package/src/templates/skills/agentkit-deploy/SKILL.md +6 -0
  46. package/src/templates/skills/agentkit-evals/SKILL.md +12 -3
  47. package/src/templates/skills/agentkit-improve/SKILL.md +86 -0
  48. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  49. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  50. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  51. package/src/templates/skills/agentkit-integrations/SKILL.md +1 -0
  52. package/src/templates/skills/agentkit-knowledge/SKILL.md +4 -1
  53. package/src/templates/skills/agentkit-provider/SKILL.md +4 -1
  54. package/src/templates/skills/agentkit-security/SKILL.md +3 -2
  55. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +9 -0
  56. package/src/templates/support.ts +4 -2
package/README.md CHANGED
@@ -44,6 +44,9 @@ agentkit db migrate
44
44
  agentkit sync run
45
45
  agentkit eval run
46
46
  agentkit eval from-conversation <conversation-id>
47
+ agentkit improve collect --deploy --since 24h
48
+ agentkit improve evals .agentkit/improve/<run>
49
+ agentkit replay .agentkit/improve/<run> --against local
47
50
  agentkit conversations list
48
51
  agentkit conversations trace <conversation-id>
49
52
  ```
@@ -6,7 +6,7 @@ Add a hosted messaging channel to an Agent Capsule, create the hosted channel re
6
6
 
7
7
  ## When To Use It
8
8
 
9
- Use this when the agent should receive messages from website chat, Telegram, or WhatsApp through AgentKit-owned webhook infrastructure.
9
+ Use this when the agent should receive messages from website chat, Telegram, WhatsApp, or Discord through AgentKit-owned channel infrastructure.
10
10
 
11
11
  ## Commands
12
12
 
@@ -17,6 +17,8 @@ agentkit channels list
17
17
  agentkit channels add website website-chat
18
18
  agentkit channels add telegram support-telegram
19
19
  agentkit channels add whatsapp support-whatsapp --provider zapster
20
+ agentkit channels connect discord support-discord
21
+ agentkit channels connect discord server-discord --mode bot
20
22
  agentkit channels setup support-telegram
21
23
  agentkit channels status support-telegram
22
24
  agentkit channels test support-telegram --message "hello"
@@ -28,7 +30,7 @@ Use `--api <url>` only when the owner gives you a non-default AgentKit Cloud API
28
30
 
29
31
  ## Files Created Or Edited
30
32
 
31
- - `agentkit.config.ts`: declare channel config with `websiteChannel`, `telegramChannel`, or `whatsappChannel`.
33
+ - `agentkit.config.ts`: declare channel config with `websiteChannel`, `telegramChannel`, `whatsappChannel`, or `discordChannel`.
32
34
  - `.agentkit/deploy.json`: written by `agentkit deploy`; used by `agentkit channels ...`.
33
35
  - No user Turso tables: AgentKit owns channel resources, dedupe, identities, queue state, and delivery logs.
34
36
  - Website channel clients must send `AGENTKIT_WEBSITE_CHANNEL_TOKEN` as `Authorization: Bearer <token>` or `X-AgentKit-Channel-Token`.
@@ -36,7 +38,7 @@ Use `--api <url>` only when the owner gives you a non-default AgentKit Cloud API
36
38
  ## Minimal Working Example
37
39
 
38
40
  ```ts
39
- import { defineAgent, telegramChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
41
+ import { defineAgent, discordChannel, telegramChannel, whatsappChannel, websiteChannel } from "@andreprado/agentkit";
40
42
 
41
43
  export default defineAgent({
42
44
  name: "support-agent",
@@ -49,6 +51,8 @@ export default defineAgent({
49
51
  websiteChannel({ name: "website-chat" }),
50
52
  telegramChannel({ name: "support-telegram" }),
51
53
  whatsappChannel({ name: "support-whatsapp", provider: "zapster" }),
54
+ discordChannel({ name: "support-discord" }),
55
+ discordChannel({ name: "server-discord", mode: "bot" }),
52
56
  ],
53
57
  access: { mode: "public" },
54
58
  storage: { driver: "agentkit" },
@@ -87,9 +91,11 @@ agentkit channels buffers clear support-whatsapp <conversation-id>
87
91
  agentkit channels buffers retry support-whatsapp <conversation-id>
88
92
  ```
89
93
 
94
+ Discord supports buffering for slash-command interactions and bot-mode server messages, but it does not support `audio` in V1.
95
+
90
96
  ## Auto Transcribe Audio
91
97
 
92
- Use `transcription` at the agent level and `audio.mode: "transcribe"` on each channel that should accept voice notes or audio files.
98
+ Use `transcription` at the agent level and `audio.mode: "transcribe"` on each Telegram or WhatsApp channel that should accept voice notes or audio files.
93
99
 
94
100
  ```ts
95
101
  export default defineAgent({
@@ -178,10 +184,10 @@ Run `agentkit deploy` before creating hosted channel resources.
178
184
  Set the named hosted secret. Do not add production values to `.env`.
179
185
 
180
186
  `channel_signature_invalid`:
181
- The provider webhook secret, token, or origin header does not match the managed secret.
187
+ The provider webhook secret, token, origin header, or Discord Ed25519 signature does not match the managed secret.
182
188
 
183
189
  `channel_limit_exceeded`:
184
- The channel daily message limit was reached. Website requests return `429`; Telegram and WhatsApp are acknowledged and skipped to avoid provider retry storms.
190
+ The channel daily message limit was reached. Website requests return `429`; Telegram, WhatsApp, and Discord are acknowledged and skipped to avoid provider retry storms.
185
191
 
186
192
  `transcription_secret_missing`:
187
193
  Set the managed transcription secret declared by `agentkit inspect`, for example `OPENAI_API_KEY` or `GROQ_API_KEY`.
@@ -77,8 +77,17 @@ agentkit knowledge search "refund policy" --top-k 3
77
77
 
78
78
  `knowledge add` is useful for one-off local indexing. `knowledge sync` validates and indexes all configured `knowledge.sources` on demand. `agentkit dev` and `agentkit chat` also sync configured Knowledge automatically before local runs, and unchanged files are skipped by content hash.
79
79
 
80
+ On Windows PowerShell, if `npm.ps1` is blocked by `PSSecurityException`, run capsule scripts through the `.cmd` shim:
81
+
82
+ ```sh
83
+ npm.cmd run agentkit -- knowledge sync
84
+ npm.cmd run agentkit -- knowledge search "refund policy" --top-k 3
85
+ ```
86
+
80
87
  When embeddings are configured locally, AgentKit stores canonical Knowledge chunks in `.agentkit/agentkit.db` and rebuilds a local libSQL vector sidecar at `.agentkit/agentkit.vectors.db`. Local semantic search uses the sidecar's native `libsql_vector_idx` path and falls back to stored JSON embeddings if the native vector path is unavailable.
81
88
 
89
+ Local lexical search uses SQLite FTS5 when the local SQLite build provides it. If SQLite does not provide FTS5, AgentKit automatically keeps indexing and searching with a normal SQLite table and a simpler text-match fallback.
90
+
82
91
  ## Agent Behavior
83
92
 
84
93
  When `knowledge` is configured, AgentKit automatically registers the internal tool `agentkit_search_knowledge` during chat runs 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, or chunk IDs.
@@ -131,4 +140,5 @@ Local `agentkit knowledge add`, `agentkit knowledge sync`, `agentkit dev`, and `
131
140
  - `Knowledge source paths must stay inside the Agent Capsule`: move the source under the capsule root, usually `knowledge/`.
132
141
  - `Local Knowledge currently supports .md, .txt, and .csv files`: convert the source or add a tool for unsupported formats.
133
142
  - `Knowledge embeddings require missing secret`: set the env var named by `knowledge.embedding.secret`.
143
+ - `PSSecurityException` on Windows PowerShell: use `npm.cmd run agentkit -- knowledge sync` or `npm.cmd run agentkit -- knowledge search "refund policy" --top-k 3`.
134
144
  - Hosted build says Turso is required: add `storage.database.driver: "turso"` before deploying Knowledge.
@@ -13,6 +13,7 @@ Managed Composio is paid hosted AgentKit infrastructure:
13
13
  - It works per agent/project, not per client.
14
14
  - It requires an AgentKit Cloud account with `managed_composio`.
15
15
  - AgentKit Cloud injects `COMPOSIO_API_KEY`; do not put it in `.env`, `.env.schema`, or `agentkit.config.ts`.
16
+ - AgentKit Cloud resolves toolkit auth configs from its managed registry. The capsule owner only declares allowed toolkits/actions.
16
17
  - AgentKit Cloud assigns the deployed Composio `user_id` from the account, project, agent, and integration name. The local inspect/build id is only a preview.
17
18
  - The agent gets one generated tool, `agentkit_composio_execute`, only when explicit Composio action slugs are configured.
18
19
  - Anonymous deploys cannot use managed Composio.
@@ -71,9 +72,10 @@ agentkit integrations status --toolkit googlecalendar
71
72
 
72
73
  Expected readiness:
73
74
 
74
- - `cloudflare_deploy_alpha` is active.
75
+ - Hosted deploy access is active through `cloudflare_deploy_alpha` or purchased/manual deploy slots.
75
76
  - `managed_composio` is active.
76
77
  - `COMPOSIO_API_KEY` appears as an AgentKit-managed secret, not a user-managed hosted secret.
78
+ - Each configured toolkit auth config is available in AgentKit Cloud.
77
79
 
78
80
  ## Connect Apps
79
81
 
@@ -150,7 +152,7 @@ Log in with a paid AgentKit Cloud account that has `managed_composio`.
150
152
 
151
153
  `managed_composio_auth_config_missing`:
152
154
 
153
- The AgentKit Cloud account is entitled, but the requested toolkit is not available for managed Composio yet. Report the exact error code and toolkit slug to the AgentKit owner.
155
+ The AgentKit Cloud account is entitled, but the requested toolkit is not configured in AgentKit Cloud yet. Report the exact error code and toolkit slug to the AgentKit owner.
154
156
 
155
157
  `managed_composio_not_configured`:
156
158
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Goal
4
4
 
5
- Configure website, Telegram, and WhatsApp channels without leaking secrets, storing raw provider payloads, or treating public webhook URLs as authorization.
5
+ Configure website, Telegram, WhatsApp, and Discord channels without leaking secrets, storing raw provider payloads, or treating public webhook URLs as authorization.
6
6
 
7
7
  ## When To Use It
8
8
 
@@ -31,6 +31,7 @@ agentkit channels deliveries show <delivery-id>
31
31
  - Keep provider tokens, webhook secrets, bot tokens, transcription keys, and bearer tokens out of source files.
32
32
  - Put secret names in `agentkit.config.ts`; put local values in ignored `.env`; upload production values with `agentkit secret set` or `agentkit secret sync`.
33
33
  - Do not store raw webhook bodies, raw audio, or provider secret values in tools, prompts, evals, fixtures, or delivery notes.
34
+ - Do not expose Discord interaction tokens or bot tokens. Interaction tokens are reply tokens, not public identifiers.
34
35
  - Inspect delivery IDs, hashes, redacted metadata, and statuses instead of raw provider payloads.
35
36
  - Keep channel plumbing out of the agent's application database. The user's Turso tables are for the agent's business data.
36
37
  - Enable audio transcription only when the capsule declares a transcription provider and bounded `limits`.
@@ -76,6 +77,29 @@ TELEGRAM_WEBHOOK_SECRET: missing
76
77
  GROQ_API_KEY: set
77
78
  ```
78
79
 
80
+ Discord slash-command mode uses a public key rather than a shared webhook secret:
81
+
82
+ ```ts
83
+ discordChannel({
84
+ name: "support-discord",
85
+ secrets: ["DISCORD_PUBLIC_KEY"],
86
+ });
87
+ ```
88
+
89
+ AgentKit validates `X-Signature-Ed25519` and `X-Signature-Timestamp` against the raw body, returns `type: 1` for Discord `PING`, and sends follow-up replies with `allowed_mentions: { parse: [] }`.
90
+
91
+ Discord bot mode uses a bot token and Gateway connection:
92
+
93
+ ```ts
94
+ discordChannel({
95
+ name: "server-discord",
96
+ mode: "bot",
97
+ secrets: ["DISCORD_BOT_TOKEN"],
98
+ });
99
+ ```
100
+
101
+ Bot mode requires Message Content Intent in the Discord Developer Portal and channel permissions for `View Channel`, `Read Message History`, and `Send Messages`. AgentKit must redact `DISCORD_BOT_TOKEN` anywhere delivery, queue, buffer, or doctor output is returned.
102
+
79
103
  ## Verification
80
104
 
81
105
  ```sh
@@ -104,7 +128,7 @@ Use the redacted delivery metadata and avoid pasting full phone numbers into com
104
128
  Set the named hosted secret with `agentkit secret set <NAME> --from-local-env` or `agentkit secret sync --from-local`.
105
129
 
106
130
  `channel_signature_invalid`:
107
- Check that the provider webhook secret/token configured in the provider dashboard matches the hosted secret name declared by the channel.
131
+ Check that the provider webhook secret/token configured in the provider dashboard matches the hosted secret name declared by the channel. For Discord slash-command mode, check that `DISCORD_PUBLIC_KEY` matches the application's public key. For Discord bot mode, check that `DISCORD_BOT_TOKEN` is set and Message Content Intent is enabled.
108
132
 
109
133
  Raw audio appears in files or logs:
110
134
  Remove it. AgentKit may pass transcript text into the normalized agent message after successful transcription, but raw audio belongs outside committed capsule files.
@@ -0,0 +1,178 @@
1
+ # Connect Discord
2
+
3
+ ## Goal
4
+
5
+ Connect Discord to a hosted AgentKit channel. Discord has two supported modes:
6
+
7
+ - `interactions`: slash commands through Discord's Interactions Endpoint URL.
8
+ - `bot`: normal server messages through a Discord Bot user connected to the Gateway.
9
+
10
+ Use `bot` mode when the agent should answer messages without a slash command.
11
+
12
+ ## Commands
13
+
14
+ Slash-command mode:
15
+
16
+ ```sh
17
+ agentkit deploy
18
+ agentkit secret set DISCORD_PUBLIC_KEY --stdin
19
+ agentkit channels connect discord support-discord
20
+ agentkit channels test support-discord --message "hello"
21
+ agentkit channels deliveries list support-discord
22
+ ```
23
+
24
+ Bot/server-message mode:
25
+
26
+ ```sh
27
+ agentkit deploy
28
+ agentkit secret set DISCORD_BOT_TOKEN --stdin
29
+ agentkit channels connect discord server-discord --mode bot
30
+ agentkit channels test server-discord --message "hello"
31
+ agentkit channels deliveries list server-discord
32
+ ```
33
+
34
+ ## Minimal Config
35
+
36
+ Slash commands:
37
+
38
+ ```ts
39
+ discordChannel({ name: "support-discord" })
40
+ ```
41
+
42
+ Normal server messages:
43
+
44
+ ```ts
45
+ discordChannel({
46
+ name: "server-discord",
47
+ mode: "bot",
48
+ })
49
+ ```
50
+
51
+ Full example:
52
+
53
+ ```ts
54
+ import { defineAgent, discordChannel } from "@andreprado/agentkit";
55
+
56
+ export default defineAgent({
57
+ name: "support-agent",
58
+ runtime: "edge",
59
+ provider: { name: "test", model: "fake" },
60
+ instructions: "./prompts/instructions.md",
61
+ secrets: [],
62
+ tools: [],
63
+ channels: [
64
+ discordChannel({
65
+ name: "server-discord",
66
+ mode: "bot",
67
+ buffer: {
68
+ mode: "debounce",
69
+ quietWindowMs: 1500,
70
+ maxWaitMs: 8000,
71
+ maxMessages: 20,
72
+ maxChars: 8000,
73
+ },
74
+ }),
75
+ ],
76
+ access: { mode: "public" },
77
+ storage: { driver: "agentkit" },
78
+ });
79
+ ```
80
+
81
+ Discord audio transcription is not supported in V1. Do not add `audio` to a Discord channel.
82
+
83
+ ## Slash Command Setup
84
+
85
+ Use this when users should run `/ask message:<text>`.
86
+
87
+ Required secret:
88
+
89
+ ```txt
90
+ DISCORD_PUBLIC_KEY
91
+ ```
92
+
93
+ `agentkit channels connect discord support-discord` creates or refreshes the hosted channel, validates the public key, runs an AgentKit synthetic smoke, and prints the human setup step.
94
+
95
+ Expected webhook URL:
96
+
97
+ ```txt
98
+ https://<deploy-host>/channels/support-discord/discord/discord/webhook
99
+ ```
100
+
101
+ In the Discord Developer Portal:
102
+
103
+ 1. Open the application.
104
+ 2. Copy the application's public key into the hosted secret named `DISCORD_PUBLIC_KEY`.
105
+ 3. Paste the AgentKit webhook URL into `Interactions Endpoint URL`.
106
+ 4. Register a slash command with a string option named `message`, `text`, `prompt`, `question`, `query`, or `input`.
107
+
108
+ AgentKit answers Discord's `PING` handshake with `{ "type": 1 }`. Normal command webhooks are acknowledged with a deferred response and the retryable channel worker sends the final answer as an interaction follow-up.
109
+
110
+ ## Bot Setup
111
+
112
+ Use this when the agent should behave like a server member and answer normal messages.
113
+
114
+ Required secret:
115
+
116
+ ```txt
117
+ DISCORD_BOT_TOKEN
118
+ ```
119
+
120
+ `agentkit channels connect discord server-discord --mode bot` creates or refreshes the hosted channel, validates the bot token secret is present, runs an AgentKit synthetic Gateway smoke, and prints the human setup step.
121
+
122
+ In the Discord Developer Portal:
123
+
124
+ 1. Create or open the Discord application.
125
+ 2. Open the Bot page.
126
+ 3. Reset/copy the bot token and save it as hosted secret `DISCORD_BOT_TOKEN`.
127
+ 4. Enable Message Content Intent on the Bot page.
128
+ 5. Install the app into the server with bot permissions.
129
+ 6. Grant the bot `View Channel`, `Read Message History`, and `Send Messages` in the channels it should answer.
130
+
131
+ Hosted AgentKit runs a Discord Gateway worker for bot-mode channels. Discord sends `MESSAGE_CREATE` events, AgentKit ignores messages authored by bots, maps each human message to a channel conversation, runs the agent, and replies in the same Discord channel with `allowed_mentions: { parse: [] }`.
132
+
133
+ For server hygiene, install or grant the bot only in channels where it should answer. Bot mode processes every readable non-bot text message the Gateway sends for that bot.
134
+
135
+ ## Safety Rules
136
+
137
+ - Keep `DISCORD_PUBLIC_KEY` and `DISCORD_BOT_TOKEN` as managed hosted secrets; do not put values in prompts, fixtures, or source files.
138
+ - Discord interaction tokens and bot tokens must never appear in delivery, queue, buffer, or doctor API responses.
139
+ - Slash-command validation uses `X-Signature-Ed25519` and `X-Signature-Timestamp` against the exact raw request body.
140
+ - Bot mode requires Discord Message Content Intent; without it, Discord sends empty message content and AgentKit skips the event.
141
+ - Outbound Discord sends use `allowed_mentions: { parse: [] }` so agent text cannot accidentally ping users or roles.
142
+ - Only set `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` in tests when Discord should not receive a real reply. Dry-run deliveries are recorded as `adapter_stubbed`.
143
+
144
+ ## Verification
145
+
146
+ ```sh
147
+ agentkit channels status server-discord
148
+ agentkit channels test server-discord --message "hello"
149
+ agentkit channels deliveries list server-discord
150
+ agentkit channels deliveries show <delivery-id>
151
+ agentkit channels buffers list server-discord
152
+ ```
153
+
154
+ Expected bot-mode flow:
155
+
156
+ 1. A user sends a normal message in a Discord server channel where the bot has access.
157
+ 2. Discord sends `MESSAGE_CREATE` over the Gateway.
158
+ 3. AgentKit records an inbound delivery and enqueues the channel job.
159
+ 4. The channel queue runs the agent.
160
+ 5. AgentKit sends a bot message through `/channels/<channel_id>/messages`.
161
+ 6. Delivery status becomes `provider_sent` for a real provider send or `adapter_stubbed` in dry-run mode.
162
+
163
+ ## Troubleshooting
164
+
165
+ `channel_secret_missing`:
166
+ Set `DISCORD_PUBLIC_KEY` for slash-command mode or `DISCORD_BOT_TOKEN` for bot mode as a hosted managed secret.
167
+
168
+ Bot does not answer normal messages:
169
+ Confirm the channel was created with `--mode bot`, `DISCORD_BOT_TOKEN` is set, Message Content Intent is enabled in the Discord Developer Portal, and the bot has channel permissions to view, read history, and send messages.
170
+
171
+ Bot answers nothing and delivery events show empty content:
172
+ Discord Message Content Intent is missing, disabled, or not approved for the application.
173
+
174
+ Discord Developer Portal rejects the slash-command endpoint:
175
+ Confirm the deployed interaction channel is online, `DISCORD_PUBLIC_KEY` matches the application's public key, and the endpoint returns `{ "type": 1 }` for Discord's signed `PING` request.
176
+
177
+ No answer appears after a queued delivery:
178
+ Run `agentkit channels deliveries list <name>`, inspect the inbound delivery, and drain/check the channel queue.
@@ -39,6 +39,19 @@ cd support-demo
39
39
  npm run agentkit -- tool lookup_order --input '{"orderId":"A100"}'
40
40
  ```
41
41
 
42
+ ## Windows PowerShell
43
+
44
+ If PowerShell blocks `npm.ps1` or `npx.ps1` with `PSSecurityException`, run the same commands through the Windows command shims:
45
+
46
+ ```sh
47
+ npx.cmd @andreprado/agentkit@alpha new demo --template blank
48
+ npm.cmd run typecheck
49
+ npm.cmd run chat -- --message "hello"
50
+ npm.cmd run agentkit -- inspect
51
+ ```
52
+
53
+ This keeps the capsule workflow the same without changing the machine-wide PowerShell execution policy.
54
+
42
55
  ## Files Created Or Edited
43
56
 
44
57
  Generated files:
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Goal
4
4
 
5
- Diagnose website, Telegram, or WhatsApp channel setup, webhook validation, dedupe, buffering, outbound sends, and delivery failures from the Agent Capsule CLI.
5
+ Diagnose website, Telegram, WhatsApp, or Discord channel setup, webhook validation, dedupe, buffering, outbound sends, and delivery failures from the Agent Capsule CLI.
6
6
 
7
7
  ## When To Use It
8
8
 
@@ -87,11 +87,17 @@ The channel was disabled. Re-add or recreate it.
87
87
  The hosted secret metadata says a required channel secret is missing. Set it with `agentkit secret set <NAME> --from-local-env` or `agentkit secret sync --from-local`.
88
88
 
89
89
  `channel_signature_invalid`:
90
- Provider authenticity validation failed. Check the provider webhook secret, token, or origin settings.
90
+ Provider authenticity validation failed. Check the provider webhook secret, token, origin settings, or Discord public key.
91
91
 
92
92
  `channel_payload_invalid`:
93
93
  The provider payload is malformed or does not match the route provider.
94
94
 
95
+ Discord endpoint validation fails in the Developer Portal:
96
+ Confirm `DISCORD_PUBLIC_KEY` is set from the application's public key and the webhook URL is `/channels/<name>/discord/discord/webhook`. AgentKit must validate Discord's signature headers before returning the `PING` PONG.
97
+
98
+ Discord bot does not answer normal server messages:
99
+ Confirm the channel was created with `--mode bot`, `DISCORD_BOT_TOKEN` is set, Message Content Intent is enabled in the Discord Developer Portal, the app is installed into the server, and the bot has `View Channel`, `Read Message History`, and `Send Messages` permissions for the channel.
100
+
95
101
  `audio_received`:
96
102
  The webhook contained a supported audio message and the channel is entering the audio handling path.
97
103
 
@@ -0,0 +1,151 @@
1
+ # Improve From Production
2
+
3
+ ## Goal
4
+
5
+ Pull hosted or local conversation evidence into the Agent Capsule, turn it into regression evals, let the local coding agent patch the capsule, and replay before deploying again.
6
+
7
+ ## When To Use This
8
+
9
+ Use this when a deployed agent gave a wrong answer, failed a tool call, mishandled a channel message, or needs production behavior converted into eval coverage.
10
+
11
+ AgentKit Cloud only exports redacted evidence. The local coding agent owns source edits, evals, replay, and deploy.
12
+
13
+ ## Commands
14
+
15
+ Collect evidence from the last hosted deploy:
16
+
17
+ ```sh
18
+ agentkit improve collect --deploy --since 24h
19
+ ```
20
+
21
+ When the CLI is logged in to AgentKit Cloud, this command first asks the control plane for deploy evidence such as failed channel deliveries, deploy errors, and conversation IDs that need review. It then reads replayable hosted conversation traces from the deployed runtime with the deploy access token. If Cloud auth is not available, it still collects hosted conversations directly from the deploy URL.
22
+
23
+ Hosted conversation reads require a deploy access token even when the chat endpoint is public. `agentkit deploy` normally writes `.agentkit/chat-access-token.json`; refresh it with:
24
+
25
+ ```sh
26
+ agentkit access token create agentkit-chat-ui --out .agentkit/chat-access-token.json
27
+ ```
28
+
29
+ Collect one hosted conversation:
30
+
31
+ ```sh
32
+ agentkit improve collect --deploy --conversation-id <conversation-id>
33
+ ```
34
+
35
+ Collect local conversations instead:
36
+
37
+ ```sh
38
+ agentkit improve collect --since 7d
39
+ ```
40
+
41
+ Generate regression evals from the collected bundle:
42
+
43
+ ```sh
44
+ agentkit improve evals .agentkit/improve/<run>
45
+ ```
46
+
47
+ Replay the bundle against the local capsule:
48
+
49
+ ```sh
50
+ agentkit replay .agentkit/improve/<run> --against local
51
+ ```
52
+
53
+ ## Files Created Or Edited
54
+
55
+ Evidence bundle, ignored local state:
56
+
57
+ ```txt
58
+ .agentkit/improve/<run>/
59
+ bundle.json
60
+ report.json
61
+ traces/
62
+ ```
63
+
64
+ Generated regression evals, committed source:
65
+
66
+ ```txt
67
+ evals/regressions/
68
+ improve-<conversation>.eval.ts
69
+ ```
70
+
71
+ The local coding agent may then edit:
72
+
73
+ ```txt
74
+ prompts/instructions.md
75
+ agentkit.config.ts
76
+ tools/
77
+ knowledge/
78
+ evals/
79
+ ```
80
+
81
+ Do not edit `.agentkit/improve/<run>/bundle.json` by hand.
82
+
83
+ ## Workflow
84
+
85
+ ```sh
86
+ agentkit improve collect --deploy --since 24h
87
+ agentkit improve evals .agentkit/improve/<run>
88
+ agentkit replay .agentkit/improve/<run> --against local
89
+ ```
90
+
91
+ Then let the local coding agent inspect `report.json`, the generated eval files, prompts, tools, and Knowledge sources. After edits:
92
+
93
+ ```sh
94
+ npm run typecheck
95
+ npm run agentkit -- inspect
96
+ npm run eval
97
+ agentkit replay .agentkit/improve/<run> --against local
98
+ agentkit deploy --smoke "hello"
99
+ ```
100
+
101
+ ## Safety Rules
102
+
103
+ - Do not paste secrets into evals, prompts, Knowledge files, or reports.
104
+ - Keep `.agentkit/improve/` out of commits.
105
+ - Review generated eval assertions before committing them. AgentKit redacts common email, phone, bearer token, and key patterns in generated eval text, but the local coding agent must still remove or generalize domain-specific client PII.
106
+ - For write, delete, payment, email, or customer-system tools, branch inside the tool on `ctx.runtime.environment === "eval"` and return deterministic non-destructive output.
107
+ - Treat hosted traces as customer evidence.
108
+ - If replay uses a real provider instead of `test/fake`, tell the owner because it may cost money and may be nondeterministic.
109
+
110
+ ## Verification
111
+
112
+ ```sh
113
+ npm run typecheck
114
+ npm run agentkit -- inspect
115
+ npm run eval
116
+ agentkit replay .agentkit/improve/<run> --against local
117
+ ```
118
+
119
+ Expected:
120
+
121
+ - `improve collect` writes a bundle and report under `.agentkit/improve/`.
122
+ - Hosted collection includes a redacted `evidence` summary in `bundle.json` and `report.json` when AgentKit Cloud evidence export is available.
123
+ - `improve evals` writes eval files under `evals/regressions/`.
124
+ - `replay` reports passed, failed, and skipped traces.
125
+ - No production secret values appear in generated files.
126
+
127
+ ## Troubleshooting
128
+
129
+ `No .agentkit/deploy.json found`:
130
+
131
+ Run `agentkit deploy` first, or collect local evidence without `--deploy`.
132
+
133
+ `deploy_conversation_request_failed`:
134
+
135
+ Refresh the deploy chat token with `agentkit access token create agentkit-chat-ui --out .agentkit/chat-access-token.json`, then retry.
136
+
137
+ `improve_evidence_store_not_configured`:
138
+
139
+ The Cloud API does not expose deploy evidence export yet. The CLI falls back to hosted conversation trace collection when possible.
140
+
141
+ `conversation_access_not_configured`:
142
+
143
+ The hosted runtime is not configured with a deploy access-token gate for conversation reads. Redeploy through AgentKit Cloud so the runtime gate is injected, or configure an explicit deploy/private token for local hosted testing.
144
+
145
+ `trace has no user turns`:
146
+
147
+ The trace cannot become a useful conversation eval. Keep the report for diagnosis, but do not commit an empty eval.
148
+
149
+ Generated eval is too strict:
150
+
151
+ Edit the eval to assert the important behavior, such as tool input, safety wording, or knowledge source usage, instead of exact prose.
@@ -25,7 +25,18 @@ npm run agentkit -- db migrate
25
25
  npm run chat -- --message "hello"
26
26
  ```
27
27
 
28
- All scaffold, local dev, chat, eval, inspect, database, and build commands are token-free. Hosted production deploy and hosted AgentKit Cloud changes require an invited AgentKit Cloud token:
28
+ All scaffold, local dev, chat, eval, inspect, database, and build commands are token-free. Hosted production deploy and hosted AgentKit Cloud changes require an AgentKit Cloud account token with hosted deploy access.
29
+
30
+ If the user does not have a token yet, start checkout from the CLI, finish Stripe Checkout in the browser, then claim the one-time checkout intent:
31
+
32
+ ```sh
33
+ npm run agentkit -- billing checkout --slots 1 --email user@example.com
34
+ npm run agentkit -- billing claim billint_... --secret bsec_...
35
+ ```
36
+
37
+ The claim command stores the returned `agk_user_...` token in the local AgentKit Cloud auth file. Treat the `bsec_...` checkout secret like a password; it exists only to claim the first token after checkout.
38
+
39
+ If the user already has a token:
29
40
 
30
41
  ```sh
31
42
  npm run agentkit -- login --token agk_user_...
@@ -42,7 +53,15 @@ OPENAI_API_KEY=sk-...
42
53
  ```
43
54
 
44
55
  `.env` is local-only. Hosted deploy secrets are handled by AgentKit outside the capsule.
45
- Closed-alpha hosted deploys require an invited account token with `cloudflare_deploy_alpha`.
56
+ Hosted deploys require an account with either `cloudflare_deploy_alpha` or purchased/manual deploy slots. Deploy slots belong to the account, not to a specific token string.
57
+
58
+ To generate or switch account tokens after login:
59
+
60
+ ```sh
61
+ npm run agentkit -- account token create new-laptop --use
62
+ npm run agentkit -- account token list
63
+ npm run agentkit -- account token revoke apitok_...
64
+ ```
46
65
 
47
66
  ## What The Agent Should Edit
48
67
 
@@ -126,6 +145,7 @@ For a final end-to-end test, run:
126
145
 
127
146
  ```sh
128
147
  npm run agentkit -- login --token agk_user_...
148
+ npm run agentkit -- account token list
129
149
  npm run agentkit -- secret sync --from-local
130
150
  npm run agentkit -- secret list
131
151
  npm run agentkit -- deploy --smoke "hello"
@@ -134,7 +154,7 @@ npm run agentkit -- chat-ui --deploy
134
154
  npm run agentkit -- access token list
135
155
  ```
136
156
 
137
- For private hosted deploys, `npm run agentkit -- deploy` writes the local chat/UI access token to `.agentkit/chat-access-token.json`. Use `npm run agentkit -- deploy --smoke "hello"` for the official hosted chat smoke, and use `npm run agentkit -- chat-ui --deploy` for hosted UI testing. The hosted Chat UI shows the conversation id, tool calls, tool errors, and a new-conversation control; use `npm run agentkit -- conversations trace <conversation-id> --deploy` to pull the hosted trace from the last deploy. Use `npm run agentkit -- access token create <name> --out <path>` only for additional clients.
157
+ For hosted deploys, `npm run agentkit -- deploy` writes the local chat/UI access token to `.agentkit/chat-access-token.json`. Use `npm run agentkit -- deploy --smoke "hello"` for the official hosted chat smoke, and use `npm run agentkit -- chat-ui --deploy` for hosted UI testing. The hosted Chat UI shows the conversation id, tool calls, tool errors, and a new-conversation control; use `npm run agentkit -- conversations trace <conversation-id> --deploy` to pull the hosted trace from the last deploy. Use `npm run agentkit -- access token create <name> --out <path>` only for additional clients.
138
158
 
139
159
  When the UI is running, open the printed `Chat:` URL and tell the owner the exact URL. If the capsule is still on `test/fake`, say the UI was tested only with the deterministic fake provider.
140
160
 
@@ -147,7 +167,7 @@ All required secret names are declared
147
167
  Prompt path exists
148
168
  Tools have input schemas
149
169
  Dangerous tools have permissions
150
- Managed Composio toolkit auth configs are present when configured
170
+ Managed Composio toolkit auth configs are available in AgentKit Cloud when configured
151
171
  Provider model is supported by AgentKit
152
172
  schema.sql is idempotent
153
173
  README/AGENTS/CLAUDE match the capsule
@@ -193,14 +213,15 @@ Before a hosted production deploy, run:
193
213
  npm run agentkit -- deploy doctor
194
214
  ```
195
215
 
196
- The doctor checks AgentKit Cloud login, Node version, alpha deploy entitlement, online deploy capacity, declared hosted secrets, local `.env` names that have not been uploaded with `npm run agentkit -- secret set`, and private-access runtime token handling. `agentkit deploy` runs the same readiness check automatically before building and uploading the artifact.
216
+ The doctor checks AgentKit Cloud login, Node version, hosted deploy entitlement, online deploy capacity, declared hosted secrets, local `.env` names that have not been uploaded with `npm run agentkit -- secret set`, and private-access runtime token handling. `agentkit deploy` runs the same readiness check automatically before building and uploading the artifact.
197
217
 
198
- If the capsule configures `composioManaged({...})`, the doctor also checks the paid `managed_composio` entitlement. `COMPOSIO_API_KEY` is AgentKit-managed in this path; the user must not set it with `agentkit secret set`.
218
+ If the capsule configures `composioManaged({...})`, the doctor also checks the paid `managed_composio` entitlement and AgentKit Cloud toolkit readiness. `COMPOSIO_API_KEY` and toolkit auth config resolution are AgentKit-managed in this path; the user must not set them with `agentkit secret set`.
199
219
 
200
220
  `alpha_access_required`:
201
221
 
202
- Log in with an invited alpha account:
222
+ Log in with an account that has hosted deploy access. If the user needs to buy slots first:
203
223
 
204
224
  ```sh
205
- npm run agentkit -- login --token agk_user_...
225
+ npm run agentkit -- billing checkout --slots 1 --email user@example.com
226
+ npm run agentkit -- billing claim billint_... --secret bsec_...
206
227
  ```