@andreprado/agentkit 0.1.0-alpha.17 → 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 (64) hide show
  1. package/README.md +3 -0
  2. package/docs/guides/add-channel.md +14 -8
  3. package/docs/guides/add-knowledge.md +10 -0
  4. package/docs/guides/add-managed-composio.md +43 -17
  5. package/docs/guides/channel-security.md +60 -39
  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 +147 -0
  9. package/docs/guides/improve-from-production.md +151 -0
  10. package/docs/guides/prepare-deploy.md +30 -14
  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 +106 -15
  16. package/docs/llms.txt +22 -4
  17. package/package.json +1 -3
  18. package/src/cli/args.ts +23 -2
  19. package/src/cli/cloud-client.ts +75 -0
  20. package/src/cli/commands/channels.ts +139 -14
  21. package/src/cli/deploy-chat-ui.ts +146 -3
  22. package/src/cli/deploy-readiness.ts +57 -1
  23. package/src/cli/help.ts +32 -8
  24. package/src/cli/index.ts +447 -17
  25. package/src/create-project.ts +13 -2
  26. package/src/index.ts +46 -3
  27. package/src/providers/pi.ts +49 -15
  28. package/src/runtime/channel-test-harness.ts +4 -1
  29. package/src/runtime/channels/discord.ts +887 -0
  30. package/src/runtime/channels.ts +15 -0
  31. package/src/runtime/config.ts +39 -3
  32. package/src/runtime/core/manifest.ts +2 -0
  33. package/src/runtime/dev-server.ts +149 -8
  34. package/src/runtime/evals.ts +27 -6
  35. package/src/runtime/improve.ts +868 -0
  36. package/src/runtime/inspect.ts +1 -0
  37. package/src/runtime/integrations/composio.ts +168 -2
  38. package/src/runtime/knowledge/retrieve.ts +25 -5
  39. package/src/runtime/knowledge/schema.ts +45 -1
  40. package/src/runtime/runtime-contract.ts +54 -0
  41. package/src/runtime/targets/cloudflare/build.ts +479 -194
  42. package/src/runtime/targets/vps/deploy.ts +1 -1
  43. package/src/storage/sqlite.ts +7 -2
  44. package/src/templates/skills/agentkit-capsule/SKILL.md +8 -1
  45. package/src/templates/skills/agentkit-capsule/references/docs-router.md +1 -2
  46. package/src/templates/skills/agentkit-channels/SKILL.md +6 -1
  47. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +2 -1
  48. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  49. package/src/templates/skills/agentkit-deploy/SKILL.md +6 -0
  50. package/src/templates/skills/agentkit-evals/SKILL.md +12 -3
  51. package/src/templates/skills/agentkit-improve/SKILL.md +86 -0
  52. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  53. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  54. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  55. package/src/templates/skills/agentkit-integrations/SKILL.md +12 -2
  56. package/src/templates/skills/agentkit-knowledge/SKILL.md +4 -1
  57. package/src/templates/skills/agentkit-provider/SKILL.md +4 -1
  58. package/src/templates/skills/agentkit-security/SKILL.md +3 -2
  59. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +9 -0
  60. package/src/templates/support.ts +4 -2
  61. package/docs/guides/agentkit-skills-architecture.md +0 -472
  62. package/docs/guides/channels-implementation-map.md +0 -243
  63. package/docs/guides/channels-production-handoff.md +0 -118
  64. package/docs/portable-deploy-release-checklist.md +0 -41
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"
@@ -24,19 +26,19 @@ agentkit channels deliveries list support-telegram
24
26
  agentkit channels buffers list support-telegram
25
27
  ```
26
28
 
27
- Use `--api <url>` with hosted commands when testing against a non-default AgentKit Cloud API.
29
+ Use `--api <url>` only when the owner gives you a non-default AgentKit Cloud API URL.
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
- - No user Turso tables: AgentKit channel resources, dedupe, identities, queue state, and delivery logs are control-plane owned.
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`.
35
37
 
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.
@@ -39,8 +40,13 @@ export default defineAgent({
39
40
  toolkits: ["gmail", "googlecalendar"],
40
41
  tools: {
41
42
  gmail: ["GMAIL_FETCH_EMAILS", "GMAIL_SEND_EMAIL"],
42
- googlecalendar: ["GOOGLECALENDAR_CREATE_EVENT"],
43
+ googlecalendar: [
44
+ "GOOGLECALENDAR_EVENTS_LIST",
45
+ "GOOGLECALENDAR_CREATE_EVENT",
46
+ "GOOGLECALENDAR_UPDATE_EVENT",
47
+ ],
43
48
  },
49
+ confirmExternalWrites: true,
44
50
  }),
45
51
  ],
46
52
  access: {
@@ -61,14 +67,15 @@ export default defineAgent({
61
67
  agentkit login --token agk_user_...
62
68
  agentkit deploy doctor
63
69
  agentkit deploy
64
- agentkit integrations status
70
+ agentkit integrations status --toolkit googlecalendar
65
71
  ```
66
72
 
67
73
  Expected readiness:
68
74
 
69
- - `cloudflare_deploy_alpha` is active.
75
+ - Hosted deploy access is active through `cloudflare_deploy_alpha` or purchased/manual deploy slots.
70
76
  - `managed_composio` is active.
71
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.
72
79
 
73
80
  ## Connect Apps
74
81
 
@@ -83,23 +90,41 @@ AgentKit prints a URL. Send that URL to the person who owns the app account.
83
90
 
84
91
  If the deploy has only one toolkit, `--toolkit` can be omitted.
85
92
 
86
- ## Operator Setup
93
+ ## Calendar Defaults
87
94
 
88
- Trusted AgentKit Cloud operators grant access and configure Composio auth configs:
95
+ For Google Calendar agents, include read and write actions together. Do not expose only `GOOGLECALENDAR_CREATE_EVENT`; users naturally ask to see availability before booking.
89
96
 
90
- ```sh
91
- npm run agentkit:operator -- accounts grant user@example.com --managed-composio
97
+ Use these starter actions:
98
+
99
+ ```ts
100
+ googlecalendar: [
101
+ "GOOGLECALENDAR_EVENTS_LIST",
102
+ "GOOGLECALENDAR_CREATE_EVENT",
103
+ "GOOGLECALENDAR_UPDATE_EVENT",
104
+ ]
92
105
  ```
93
106
 
94
- Required control-plane environment:
107
+ `GOOGLECALENDAR_CREATE_EVENT` requires extra care:
95
108
 
96
- ```txt
97
- AGENTKIT_SECRET_COMPOSIO_API_KEY=<project API key>
98
- AGENTKIT_COMPOSIO_AUTH_CONFIG_GMAIL=<auth config id>
99
- AGENTKIT_COMPOSIO_AUTH_CONFIG_GOOGLECALENDAR=<auth config id>
100
- ```
109
+ - `start_datetime` must be explicit UTC RFC3339, such as `2026-06-03T15:00:00Z` for 12:00 in `America/Sao_Paulo`.
110
+ - `event_duration_minutes` or `event_duration_hour` must be explicit. AgentKit blocks the implicit Composio default because `event_duration_minutes` defaults to 30.
111
+ - Confirm the final title, date, local time, duration, timezone, and attendees/location when relevant before creating or updating an event.
112
+
113
+ ## Write Confirmation
101
114
 
102
- Use one `AGENTKIT_COMPOSIO_AUTH_CONFIG_<TOOLKIT>` value per toolkit slug, uppercased with non-alphanumeric characters converted to `_`.
115
+ Managed Composio requires confirmation for external write actions by default. For actions such as create, update, delete, send, patch, move, insert, clear, remove, import, or quick add, the generated `agentkit_composio_execute` tool requires `confirmed: true`.
116
+
117
+ Set `confirmed: true` only after the user confirms the exact external change. If a capsule intentionally handles confirmation elsewhere, disable this guard explicitly:
118
+
119
+ ```ts
120
+ composioManaged({
121
+ toolkits: ["googlecalendar"],
122
+ tools: {
123
+ googlecalendar: ["GOOGLECALENDAR_EVENTS_LIST", "GOOGLECALENDAR_CREATE_EVENT"],
124
+ },
125
+ confirmExternalWrites: false,
126
+ })
127
+ ```
103
128
 
104
129
  ## Verification
105
130
 
@@ -107,7 +132,7 @@ Use one `AGENTKIT_COMPOSIO_AUTH_CONFIG_<TOOLKIT>` value per toolkit slug, upperc
107
132
  agentkit inspect
108
133
  agentkit build --target cloudflare
109
134
  agentkit deploy doctor
110
- agentkit integrations status
135
+ agentkit integrations status --toolkit googlecalendar
111
136
  ```
112
137
 
113
138
  Expected:
@@ -117,6 +142,7 @@ Expected:
117
142
  - Build manifest includes `integrations`.
118
143
  - Build manifest includes `COMPOSIO_API_KEY`.
119
144
  - `deploy doctor` does not ask the user to set `COMPOSIO_API_KEY`.
145
+ - `deploy doctor` reports each configured toolkit auth config as present before the connect link flow.
120
146
 
121
147
  ## Troubleshooting
122
148
 
@@ -126,11 +152,11 @@ Log in with a paid AgentKit Cloud account that has `managed_composio`.
126
152
 
127
153
  `managed_composio_auth_config_missing`:
128
154
 
129
- An operator must set `AGENTKIT_COMPOSIO_AUTH_CONFIG_<TOOLKIT>` on the control plane.
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.
130
156
 
131
157
  `managed_composio_not_configured`:
132
158
 
133
- An operator must set `AGENTKIT_SECRET_COMPOSIO_API_KEY` on the control plane.
159
+ Managed Composio is not available for this AgentKit Cloud environment. Use BYO `defineTool` wrappers for now or ask the owner to enable managed Composio for the account.
134
160
 
135
161
  `integration_toolkit_required`:
136
162
 
@@ -2,52 +2,40 @@
2
2
 
3
3
  ## Goal
4
4
 
5
- Keep channel webhooks, delivery logs, provider sends, and managed secrets safe by default.
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
 
9
- Use this before adding a channel provider, changing webhook validation, adding delivery logging, or enabling real-provider smoke tests.
9
+ Use this when a coding agent adds or changes channels in an Agent Capsule, enables audio transcription, inspects deliveries, or prepares a hosted deploy that receives provider webhooks.
10
10
 
11
11
  ## Commands
12
12
 
13
13
  ```sh
14
14
  agentkit inspect
15
15
  agentkit channels status <name>
16
+ agentkit channels doctor <name>
17
+ agentkit channels deliveries list <name> --since 24h
16
18
  agentkit channels deliveries show <delivery-id>
17
- bun test packages/agentkit/src/runtime/channels/adapters.test.ts
18
- bun test packages/agentkit/src/runtime/transcription.test.ts
19
- bun test packages/agentkit/src/runtime/deploy.test.ts
20
19
  ```
21
20
 
22
- Real-provider gates are opt-in:
23
-
24
- ```sh
25
- AGENTKIT_RUN_TELEGRAM_CHANNEL_TESTS=1 bun test
26
- AGENTKIT_RUN_ZAPSTER_CHANNEL_TESTS=1 bun test
27
- ```
28
-
29
- Telegram smoke also requires `TELEGRAM_BOT_TOKEN`, `TELEGRAM_WEBHOOK_SECRET`, and `AGENTKIT_TELEGRAM_WEBHOOK_URL`.
30
-
31
- Zapster smoke also requires `ZAPSTER_API_KEY`, `ZAPSTER_INSTANCE_ID`, and `AGENTKIT_ZAPSTER_TO`. `AGENTKIT_ZAPSTER_SEND_URL` is optional and defaults to `https://api.zapsterapi.com/v1/wa/messages`.
32
-
33
21
  ## Files Created Or Edited
34
22
 
35
- - `agentkit.config.ts`: secret names only.
36
- - Managed hosted secrets: production secret values, no readback.
37
- - Delivery records: hashes, statuses, provider event IDs, redacted metadata.
23
+ - `agentkit.config.ts`: channel names, provider choices, audio/buffer config, and secret names only.
24
+ - `.env.schema`: local secret names only when the capsule needs a local provider or local smoke.
25
+ - `.env`: local-only secret values; do not commit it.
26
+ - Hosted managed secrets: production secret values with no readback.
38
27
 
39
28
  ## Safety Rules
40
29
 
41
30
  - Public webhook URLs are not permission grants.
42
- - Validate provider authenticity when the provider supports it.
43
- - Do not store channel plumbing in the user's Turso database.
44
- - Do not store raw webhook bodies in delivery records; store a SHA-256 hash.
45
- - Do not store raw audio in delivery records. V1 audio transcription downloads provider media into memory and stores only redacted metadata and state transitions.
46
- - Redact bearer tokens, bot tokens, signing secrets, provider API tokens, and phone numbers.
47
- - Inject only channel-declared secrets into adapter code.
48
- - Inject transcription secrets only when the deploy manifest declares transcription and the channel uses `audio.mode: "transcribe"`.
49
- - Prefer acknowledging Telegram/WhatsApp over retry storms when a channel-level limit is exceeded.
50
- - Keep audio duration and byte limits bounded before provider calls to avoid uncontrolled transcription spend.
31
+ - Keep provider tokens, webhook secrets, bot tokens, transcription keys, and bearer tokens out of source files.
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
+ - 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.
35
+ - Inspect delivery IDs, hashes, redacted metadata, and statuses instead of raw provider payloads.
36
+ - Keep channel plumbing out of the agent's application database. The user's Turso tables are for the agent's business data.
37
+ - Enable audio transcription only when the capsule declares a transcription provider and bounded `limits`.
38
+ - Keep channel buffer limits bounded so bursty client messages cannot create unbounded runs or provider spend.
51
39
 
52
40
  ## Minimal Working Example
53
41
 
@@ -81,7 +69,7 @@ export default defineAgent({
81
69
  });
82
70
  ```
83
71
 
84
- The config contains secret names only. Hosted responses report:
72
+ The config contains secret names only. Hosted responses report status, not values:
85
73
 
86
74
  ```txt
87
75
  TELEGRAM_BOT_TOKEN: set
@@ -89,25 +77,58 @@ TELEGRAM_WEBHOOK_SECRET: missing
89
77
  GROQ_API_KEY: set
90
78
  ```
91
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
+
92
103
  ## Verification
93
104
 
94
105
  ```sh
95
- bun test packages/agentkit/src/runtime/channels/adapters.test.ts
96
- bun test packages/agentkit/src/runtime/transcription.test.ts
97
- bun test packages/agentkit/src/runtime/deploy.test.ts
98
- npm run typecheck
106
+ npm run agentkit -- inspect
107
+ npm run agentkit -- deploy doctor
108
+ npm run agentkit -- channels status <name>
109
+ npm run agentkit -- channels doctor <name>
110
+ ```
111
+
112
+ For a synthetic channel smoke after deploy:
113
+
114
+ ```sh
115
+ npm run agentkit -- channels test <name> --message "hello"
116
+ npm run agentkit -- channels deliveries list <name> --since 1h
99
117
  ```
100
118
 
101
119
  ## Troubleshooting
102
120
 
103
121
  Secret value appears in output:
104
- Stop and add a regression test before changing behavior. Delivery APIs must never return secret values.
122
+ Stop and remove the value from source, fixtures, prompts, evals, and delivery notes. Hosted delivery APIs must not return secret values.
105
123
 
106
124
  Phone number appears in delivery logs:
107
- Redact it to a stable partial form such as `5511******9999`.
125
+ Use the redacted delivery metadata and avoid pasting full phone numbers into committed fixtures.
126
+
127
+ `channel_secret_missing`:
128
+ Set the named hosted secret with `agentkit secret set <NAME> --from-local-env` or `agentkit secret sync --from-local`.
108
129
 
109
- Webhook accepts invalid signatures or origin headers:
110
- Fix `verifyWebhook` for the adapter before enabling provider setup docs.
130
+ `channel_signature_invalid`:
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.
111
132
 
112
- Raw audio or transcript provider secret appears in output:
113
- Stop and add a regression test before changing behavior. Delivery APIs may include transcript text in normalized agent messages after successful transcription, but must never include raw bytes or provider secret values.
133
+ Raw audio appears in files or logs:
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: