@andreprado/agentkit 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +8 -77
  2. package/docs/guides/add-channel.md +14 -92
  3. package/docs/guides/add-knowledge.md +0 -21
  4. package/docs/guides/add-tool.md +5 -11
  5. package/docs/guides/channel-security.md +3 -207
  6. package/docs/guides/connect-discord.md +7 -172
  7. package/docs/guides/connect-slack.md +6 -121
  8. package/docs/guides/connect-telegram.md +6 -165
  9. package/docs/guides/connect-whatsapp-evolution.md +6 -116
  10. package/docs/guides/connect-whatsapp-uazapi.md +6 -134
  11. package/docs/guides/connect-whatsapp-zapster.md +6 -202
  12. package/docs/guides/create-agent.md +5 -14
  13. package/docs/guides/debug-channel.md +4 -156
  14. package/docs/guides/improve-local.md +13 -0
  15. package/docs/guides/local-only-migration.md +35 -0
  16. package/docs/guides/replay-local-traces.md +11 -0
  17. package/docs/guides/run-evals.md +2 -4
  18. package/docs/guides/security-rules.md +5 -154
  19. package/docs/guides/use-jev.md +3 -6
  20. package/docs/guides/use-provider.md +5 -6
  21. package/docs/guides/write-feedback.md +10 -0
  22. package/docs/llms-full.txt +27 -448
  23. package/docs/llms.txt +8 -44
  24. package/package.json +3 -5
  25. package/src/cli/commands/channels.ts +8 -1613
  26. package/src/cli/commands/feedback.ts +8 -86
  27. package/src/cli/commands/provider.ts +29 -11
  28. package/src/cli/constants.ts +0 -3
  29. package/src/cli/flags.ts +0 -28
  30. package/src/cli/help.ts +16 -92
  31. package/src/cli/index.ts +15 -1091
  32. package/src/index.ts +6 -158
  33. package/src/providers/codex-auth.ts +16 -2
  34. package/src/providers/pi.ts +36 -19
  35. package/src/runtime/channels/discord.ts +2 -2
  36. package/src/runtime/chat.ts +5 -3
  37. package/src/runtime/config.ts +14 -148
  38. package/src/runtime/database.ts +2 -2
  39. package/src/runtime/dev-server.ts +8 -8
  40. package/src/runtime/env.ts +11 -0
  41. package/src/runtime/improve.ts +2 -262
  42. package/src/runtime/inspect.ts +13 -73
  43. package/src/runtime/knowledge/ingest.ts +1 -1
  44. package/src/runtime/knowledge/tool.ts +16 -2
  45. package/src/runtime/knowledge/vector.ts +1 -1
  46. package/src/runtime/tool-runner.ts +5 -3
  47. package/src/runtime/tools.ts +10 -14
  48. package/src/storage/sqlite.ts +11 -32
  49. package/src/templates/blank.ts +15 -102
  50. package/src/templates/common.ts +60 -0
  51. package/src/templates/dentista.ts +7 -74
  52. package/src/templates/skills/agentkit-capsule/SKILL.md +5 -7
  53. package/src/templates/skills/agentkit-capsule/references/docs-router.md +2 -3
  54. package/src/templates/skills/agentkit-channels/SKILL.md +6 -119
  55. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +0 -9
  56. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +1 -64
  57. package/src/templates/skills/agentkit-channels/references/discord.md +2 -92
  58. package/src/templates/skills/agentkit-channels/references/slack.md +2 -55
  59. package/src/templates/skills/agentkit-channels/references/telegram.md +2 -71
  60. package/src/templates/skills/agentkit-channels/references/whatsapp-evolution.md +2 -56
  61. package/src/templates/skills/agentkit-channels/references/whatsapp-uazapi.md +2 -53
  62. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +2 -70
  63. package/src/templates/skills/agentkit-database/SKILL.md +2 -4
  64. package/src/templates/skills/agentkit-evals/SKILL.md +1 -1
  65. package/src/templates/skills/agentkit-improve/SKILL.md +6 -85
  66. package/src/templates/skills/agentkit-improve/references/trace-packets.md +1 -1
  67. package/src/templates/skills/agentkit-provider/SKILL.md +1 -2
  68. package/src/templates/skills/agentkit-security/SKILL.md +1 -3
  69. package/src/templates/skills/agentkit-tools/SKILL.md +1 -1
  70. package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +1 -2
  71. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +5 -11
  72. package/src/templates/support.ts +8 -92
  73. package/docs/guides/add-managed-composio.md +0 -165
  74. package/docs/guides/improve-from-production.md +0 -151
  75. package/docs/guides/prepare-deploy.md +0 -227
  76. package/docs/guides/replay-production-traces.md +0 -72
  77. package/docs/guides/send-feedback.md +0 -135
  78. package/src/cli/cloud-client.ts +0 -377
  79. package/src/cli/deploy-chat-ui.ts +0 -606
  80. package/src/cli/deploy-readiness.ts +0 -561
  81. package/src/cloud/artifact.ts +0 -139
  82. package/src/cloud/client.ts +0 -80
  83. package/src/cloud/contracts.ts +0 -63
  84. package/src/cloud/index.ts +0 -3
  85. package/src/runtime/build.ts +0 -43
  86. package/src/runtime/core/deploy-state.ts +0 -54
  87. package/src/runtime/core/manifest.ts +0 -283
  88. package/src/runtime/core/targets.ts +0 -133
  89. package/src/runtime/deploy-readiness.ts +0 -135
  90. package/src/runtime/deploy.ts +0 -1
  91. package/src/runtime/integrations/composio.ts +0 -425
  92. package/src/runtime/targets/cloudflare/build.ts +0 -3319
  93. package/src/runtime/targets/container/build.ts +0 -146
  94. package/src/runtime/targets/container/server.ts +0 -33
  95. package/src/runtime/targets/vps/deploy.ts +0 -223
  96. package/src/templates/skills/agentkit-deploy/SKILL.md +0 -52
  97. package/src/templates/skills/agentkit-integrations/SKILL.md +0 -98
@@ -1,178 +1,13 @@
1
- # Connect Discord
1
+ # Connect Discord Locally
2
2
 
3
- ## Goal
3
+ Add `discordChannel({ name: "support-discord", mode: "interactions" })` to `channels` with `runtime: "local"`. Save `DISCORD_PUBLIC_KEY` in ignored `.env`.
4
4
 
5
- Connect Discord to a hosted AgentKit channel. Discord has two supported modes:
5
+ Set the Discord application's Interactions Endpoint URL to `https://<tunnel-host>/channels/support-discord/discord/discord/webhook`. Register a command with a string option such as `message`. AgentKit validates `X-Signature-Ed25519` and `X-Signature-Timestamp` against the raw body, responds to signed PING, and returns the agent reply inline with mentions disabled.
6
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.
7
+ Slow provider responses may exceed Discord's interaction deadline; the local runtime has no deferred-response worker. The `bot` adapter accepts forwarded message events with `DISCORD_BOT_TOKEN`, but AgentKit does not connect to the Gateway. A bot config alone cannot receive server messages; use interactions or provide your own bridge. Discord audio is unsupported.
9
8
 
10
- Use `bot` mode when the agent should answer messages without a slash command.
9
+ `agentkit inspect` reports `discord_gateway_bridge_required` for each bot-mode channel. Its adapter status remains `needs_setup` because AgentKit cannot verify an external bridge's connectivity; having a bot token does not establish a Gateway connection.
11
10
 
12
- ## Commands
11
+ Run `agentkit inspect`, `agentkit channels list`, and `agentkit dev`. Configure the provider webhook manually using an HTTPS tunnel to the printed port. Only authenticated webhook routes accept tunnel hosts; the dev UI and other APIs stay loopback-only. Keep the local process running and update registration if the tunnel hostname changes.
13
12
 
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.
13
+ Test with a correctly authenticated fixture and inspect the response, then use `agentkit conversations trace <id>`. A synthetic test does not prove real provider delivery. Use `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` when a test must not send to real recipients. Local buffering is best-effort and in-memory; no durable retry worker is included.
@@ -1,126 +1,11 @@
1
- # Connect Slack
1
+ # Connect Slack Locally
2
2
 
3
- ## Goal
3
+ Add `slackChannel({ name: "support-slack" })` to `channels` with `runtime: "local"`. Set `SLACK_BOT_TOKEN` and `SLACK_SIGNING_SECRET` in ignored `.env`.
4
4
 
5
- Connect Slack to a hosted AgentKit channel through Slack Events API.
5
+ Configure Slack Event Subscriptions with `https://<tunnel-host>/channels/support-slack/slack/slack/webhook`. Install the app with `app_mentions:read`, `im:history`, and `chat:write`, then subscribe to `app_mention` and `message.im`. AgentKit validates the raw-body signature and timestamp before answering url_verification or handling an event.
6
6
 
7
- V1 supports:
7
+ Bot/subtype messages are ignored to avoid loops. Replies use chat.postMessage with mention expansion and unfurls disabled. Socket Mode, all-channel listening, file events, and Slack audio are unsupported. Processing runs in the local webhook handler; slow responses can cause provider retries.
8
8
 
9
- - `app_mention` events in channels.
10
- - `message.im` direct messages.
11
- - Replies through `chat.postMessage`.
9
+ Run `agentkit inspect`, `agentkit channels list`, and `agentkit dev`. Configure the provider webhook manually using an HTTPS tunnel to the printed port. Only authenticated webhook routes accept tunnel hosts; the dev UI and other APIs stay loopback-only. Keep the local process running and update registration if the tunnel hostname changes.
12
10
 
13
- Slack Socket Mode, file events, audio transcription, app-management automation, and all-channel message listening are not supported in V1.
14
-
15
- ## Commands
16
-
17
- ```sh
18
- agentkit deploy
19
- agentkit secret set SLACK_BOT_TOKEN --stdin
20
- agentkit secret set SLACK_SIGNING_SECRET --stdin
21
- agentkit channels connect slack support-slack
22
- agentkit channels test support-slack --message "hello"
23
- agentkit channels deliveries list support-slack
24
- ```
25
-
26
- ## Minimal Config
27
-
28
- ```ts
29
- import { defineAgent, slackChannel } from "@andreprado/agentkit";
30
-
31
- export default defineAgent({
32
- name: "support-agent",
33
- runtime: "edge",
34
- provider: { name: "test", model: "fake" },
35
- instructions: "./prompts/instructions.md",
36
- secrets: [],
37
- tools: [],
38
- channels: [slackChannel({ name: "support-slack" })],
39
- access: { mode: "public" },
40
- storage: { driver: "agentkit" },
41
- });
42
- ```
43
-
44
- ## Slack App Setup
45
-
46
- Required hosted secrets:
47
-
48
- ```txt
49
- SLACK_BOT_TOKEN
50
- SLACK_SIGNING_SECRET
51
- ```
52
-
53
- Expected webhook URL:
54
-
55
- ```txt
56
- https://<deploy-host>/channels/support-slack/slack/slack/webhook
57
- ```
58
-
59
- In Slack app configuration:
60
-
61
- 1. Open **Basic Information** and copy the Signing Secret into hosted secret `SLACK_SIGNING_SECRET`.
62
- 2. Open **OAuth & Permissions** and add bot scopes:
63
- - `app_mentions:read`
64
- - `im:history`
65
- - `chat:write`
66
- 3. Install or reinstall the app to the workspace.
67
- 4. Copy the Bot User OAuth Token into hosted secret `SLACK_BOT_TOKEN`.
68
- 5. Open **Event Subscriptions**.
69
- 6. Enable events and paste the AgentKit webhook URL as the Request URL.
70
- 7. Subscribe to bot events:
71
- - `app_mention`
72
- - `message.im`
73
-
74
- AgentKit answers Slack `url_verification` challenges with the literal challenge string after signature validation.
75
-
76
- ## Runtime Behavior
77
-
78
- Slack signs each request with `X-Slack-Signature` and `X-Slack-Request-Timestamp`. AgentKit verifies the signature against the raw body and rejects stale timestamps before normalizing events.
79
-
80
- For channel mentions, AgentKit maps the conversation to the Slack thread and replies in that thread. For direct messages, AgentKit maps the conversation to the Slack DM channel and user.
81
-
82
- AgentKit skips Slack bot/subtype messages to avoid reply loops. Outbound Slack delivery uses `chat.postMessage` with `parse: "none"`, disabled link-name expansion, disabled unfurls, and escaped Slack control mentions.
83
-
84
- ## Safety Rules
85
-
86
- - Keep `SLACK_BOT_TOKEN` and `SLACK_SIGNING_SECRET` as managed hosted secrets; do not put values in prompts, fixtures, evals, or source files.
87
- - Do not configure `audio` on `slackChannel`; Slack audio is not supported in V1.
88
- - Keep bot scopes narrow. V1 does not require broad channel-history scopes for all-channel listening.
89
- - Only set `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` in tests when Slack should not receive a real reply.
90
- - Delivery logs return hashes and redacted metadata, never raw Slack request bodies or token values.
91
-
92
- ## Verification
93
-
94
- ```sh
95
- agentkit channels status support-slack
96
- agentkit channels test support-slack --message "hello"
97
- agentkit channels deliveries list support-slack
98
- agentkit channels deliveries show <delivery-id>
99
- agentkit channels buffers list support-slack
100
- ```
101
-
102
- Expected flow:
103
-
104
- 1. A user mentions the Slack app or sends it a direct message.
105
- 2. Slack sends a signed Events API request.
106
- 3. AgentKit records an inbound delivery and enqueues the channel job.
107
- 4. The channel queue runs the agent.
108
- 5. AgentKit sends a Slack reply through `chat.postMessage`.
109
- 6. Delivery status becomes `provider_sent` for a real provider send or `adapter_stubbed` in dry-run mode.
110
-
111
- ## Troubleshooting
112
-
113
- `channel_secret_missing`:
114
- Set `SLACK_BOT_TOKEN` and `SLACK_SIGNING_SECRET` as hosted managed secrets.
115
-
116
- Slack rejects the Request URL:
117
- Confirm the deployed channel is online, `SLACK_SIGNING_SECRET` matches the Slack app, and the endpoint can answer Slack's signed `url_verification` challenge.
118
-
119
- No channel mention arrives:
120
- Confirm Event Subscriptions includes `app_mention`, the app is installed in the workspace, and the app has access to the channel where it is mentioned.
121
-
122
- No direct message arrives:
123
- Confirm Event Subscriptions includes `message.im` and the app has `im:history`.
124
-
125
- No answer appears after a queued delivery:
126
- Run `agentkit channels deliveries list support-slack`, inspect the inbound delivery, and drain/check the channel queue.
11
+ Test with a correctly authenticated fixture and inspect the response, then use `agentkit conversations trace <id>`. A synthetic test does not prove real provider delivery. Use `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` when a test must not send to real recipients. Local buffering is best-effort and in-memory; no durable retry worker is included.
@@ -1,170 +1,11 @@
1
- # Connect Telegram
1
+ # Connect Telegram Locally
2
2
 
3
- ## Goal
3
+ Add `telegramChannel({ name: "support-telegram" })` to `channels` in a capsule with `runtime: "local"`. Set `TELEGRAM_BOT_TOKEN` and `TELEGRAM_WEBHOOK_SECRET` in ignored `.env` through `agentkit env set <NAME> --stdin`.
4
4
 
5
- Connect a Telegram bot to a hosted AgentKit channel with a stable AgentKit webhook URL.
5
+ Register `https://<tunnel-host>/channels/support-telegram/telegram/telegram/webhook` with Telegram setWebhook. Set `secret_token` to `TELEGRAM_WEBHOOK_SECRET` and `allowed_updates` to `["message"]`. AgentKit validates `X-Telegram-Bot-Api-Secret-Token` before processing. It does not register the webhook automatically.
6
6
 
7
- ## When To Use It
7
+ For audio, set top-level `transcription` and `audio: { mode: "transcribe" }` on the channel. Telegram voice notes use OGG/Opus; the current Groq adapter accepts that format. Set its declared secret (usually `GROQ_API_KEY`). AgentKit uses Telegram getFile to download media and transcribes it locally through the chosen provider. Never log a bot-token media URL.
8
8
 
9
- Use this after `telegramChannel({ name: "support-telegram" })` exists in `agentkit.config.ts` and the capsule has been deployed.
9
+ Run `agentkit inspect`, `agentkit channels list`, and `agentkit dev`. Configure the provider webhook manually using an HTTPS tunnel to the printed port. Only authenticated webhook routes accept tunnel hosts; the dev UI and other APIs stay loopback-only. Keep the local process running and update registration if the tunnel hostname changes.
10
10
 
11
- ## Commands
12
-
13
- ```sh
14
- agentkit deploy
15
- agentkit channels add telegram support-telegram
16
- agentkit channels setup support-telegram
17
- agentkit channels setup support-telegram --apply
18
- agentkit channels status support-telegram
19
- agentkit channels test support-telegram --message "hello"
20
- agentkit channels deliveries list support-telegram
21
- ```
22
-
23
- Required secrets:
24
-
25
- ```txt
26
- TELEGRAM_BOT_TOKEN
27
- TELEGRAM_WEBHOOK_SECRET
28
- ```
29
-
30
- If Telegram audio transcription is enabled, also set the transcription provider secret declared by `agentkit inspect`, usually:
31
-
32
- ```txt
33
- GROQ_API_KEY
34
- ```
35
-
36
- ## Files Created Or Edited
37
-
38
- - `agentkit.config.ts`: `telegramChannel({ name: "support-telegram" })`.
39
- - `.agentkit/deploy.json`: deploy state for resolving the hosted deploy.
40
- - No local webhook server files.
41
-
42
- ## Minimal Working Example
43
-
44
- ```ts
45
- import { defineAgent, telegramChannel } from "@andreprado/agentkit";
46
-
47
- export default defineAgent({
48
- name: "support-agent",
49
- runtime: "edge",
50
- provider: { name: "test", model: "fake" },
51
- instructions: "./prompts/instructions.md",
52
- secrets: [],
53
- tools: [],
54
- channels: [telegramChannel({ name: "support-telegram" })],
55
- access: { mode: "public" },
56
- storage: { driver: "agentkit" },
57
- });
58
- ```
59
-
60
- To answer once after a burst of Telegram messages, enable channel buffering:
61
-
62
- ```ts
63
- telegramChannel({
64
- name: "support-telegram",
65
- buffer: {
66
- mode: "debounce",
67
- quietWindowMs: 1500,
68
- maxWaitMs: 8000,
69
- maxMessages: 20,
70
- maxChars: 8000,
71
- },
72
- })
73
- ```
74
-
75
- ## Auto Transcribe Telegram Audio
76
-
77
- Telegram voice notes arrive as OGG/Opus. In V1, use Groq for the most obvious Telegram voice-note path because the AgentKit Groq adapter accepts `audio/ogg`.
78
-
79
- ```ts
80
- import { defineAgent, telegramChannel } from "@andreprado/agentkit";
81
-
82
- export default defineAgent({
83
- name: "support-agent",
84
- runtime: "edge",
85
- provider: { name: "openai", model: "gpt-5.4-mini" },
86
- instructions: "./prompts/instructions.md",
87
- transcription: {
88
- provider: "groq",
89
- model: "whisper-large-v3-turbo",
90
- secret: "GROQ_API_KEY",
91
- language: "pt",
92
- limits: {
93
- maxDurationSeconds: 180,
94
- maxBytes: 20_000_000,
95
- },
96
- },
97
- channels: [
98
- telegramChannel({
99
- name: "support-telegram",
100
- audio: {
101
- mode: "transcribe",
102
- },
103
- }),
104
- ],
105
- access: { mode: "public" },
106
- storage: { driver: "agentkit" },
107
- });
108
- ```
109
-
110
- Processing order:
111
-
112
- 1. AgentKit validates `X-Telegram-Bot-Api-Secret-Token`.
113
- 2. Telegram `voice` or `audio` payloads become normalized audio messages.
114
- 3. AgentKit records `audio_received` and enqueues a channel job before acknowledging Telegram.
115
- 4. The retryable channel worker calls Telegram `getFile`, downloads the file with `TELEGRAM_BOT_TOKEN`, and does not log the token.
116
- 5. AgentKit sends the audio bytes to the configured transcription provider using the user's managed secret.
117
- 6. The agent run receives a text message with the transcript.
118
-
119
- OpenAI transcription can be used for Telegram files that arrive as MP3, MP4, MPEG, MPGA, M4A, WAV, or WEBM. Telegram voice notes are usually OGG/Opus, so they should use Groq in V1 unless the provider payload is converted before it reaches AgentKit.
120
-
121
- ## Setup Behavior
122
-
123
- `agentkit channels setup support-telegram` is read-only and prints the webhook URL.
124
-
125
- `agentkit channels setup support-telegram --apply` calls Telegram `setWebhook` with:
126
-
127
- - `url`: the AgentKit webhook URL;
128
- - `secret_token`: `TELEGRAM_WEBHOOK_SECRET`;
129
- - `allowed_updates`: `["message"]`.
130
-
131
- Against AgentKit Cloud, `--apply` runs through the Cloud API and uses managed hosted secrets. The legacy local fallback only uses `TELEGRAM_BOT_TOKEN` and `TELEGRAM_WEBHOOK_SECRET` from the shell when the Cloud API does not expose channel setup.
132
-
133
- ## Safety Rules
134
-
135
- - Use `--apply` only when real Telegram secrets are present.
136
- - Do not paste the bot token into code, docs, test fixtures, or delivery logs.
137
- - Telegram webhook validation uses `X-Telegram-Bot-Api-Secret-Token`.
138
-
139
- ## Verification
140
-
141
- ```sh
142
- agentkit channels status support-telegram
143
- agentkit channels test support-telegram --message "hello"
144
- agentkit channels test-audio support-telegram --fixture voice-note
145
- agentkit transcribe smoke --provider groq
146
- agentkit channels deliveries show <delivery-id>
147
- ```
148
-
149
- Expected webhook URL shape:
150
-
151
- ```txt
152
- https://<deploy-host>/channels/support-telegram/telegram/telegram/webhook
153
- ```
154
-
155
- ## Troubleshooting
156
-
157
- `TELEGRAM_BOT_TOKEN and TELEGRAM_WEBHOOK_SECRET must be set`:
158
- Set both secrets before using `--apply`.
159
-
160
- `channel_signature_invalid`:
161
- The incoming Telegram secret token does not match `TELEGRAM_WEBHOOK_SECRET`.
162
-
163
- `channel_payload_invalid`:
164
- The update is malformed or is not a supported private text message.
165
-
166
- `transcription_secret_missing`:
167
- Set `GROQ_API_KEY` or the custom secret named in `transcription.secret` as a managed hosted secret.
168
-
169
- `transcription_audio_format_unsupported`:
170
- The configured transcription provider does not accept the Telegram file format. Use Groq for OGG/Opus voice notes in V1. `agentkit inspect` warns when a Telegram channel uses `audio.mode: "transcribe"` with OpenAI transcription.
11
+ Test with a correctly authenticated fixture and inspect the response, then use `agentkit conversations trace <id>`. A synthetic test does not prove real provider delivery. Use `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` when a test must not send to real recipients. Local buffering is best-effort and in-memory; no durable retry worker is included.
@@ -1,121 +1,11 @@
1
- # Connect WhatsApp Through Evolution API
1
+ # Connect WhatsApp Through Evolution Locally
2
2
 
3
- ## Goal
3
+ Add `whatsappChannel({ name: "main-whatsapp", provider: "evolution" })` to `channels` with `runtime: "local"`. Set `EVOLUTION_API_BASE_URL`, `EVOLUTION_API_KEY`, `EVOLUTION_INSTANCE_NAME`, and `EVOLUTION_WEBHOOK_TOKEN` in ignored `.env`.
4
4
 
5
- Connect a self-hosted Evolution API WhatsApp instance to a hosted AgentKit WhatsApp channel.
5
+ Register `https://<tunnel-host>/channels/main-whatsapp/whatsapp/evolution/webhook?token=<EVOLUTION_WEBHOOK_TOKEN>` with Evolution. Generate the webhook token yourself; keep the complete tokenized URL secret. The API base URL must be public HTTPS; private-network and credential-bearing URLs are rejected before forwarding credentials.
6
6
 
7
- ## When To Use It
7
+ AgentKit ignores fromMe messages, normalizes inbound text/audio, and sends replies through `/message/sendText/{instance}`. Audio transcription requires top-level `transcription` and channel `audio: { mode: "transcribe" }`; media is downloaded through `/chat/getBase64FromMediaMessage/{instance}`. A missing provider message id or missing base64 media produces an audio download error.
8
8
 
9
- Use this after `whatsappChannel({ name: "main-whatsapp", provider: "evolution" })` exists in `agentkit.config.ts` and the capsule has been deployed.
9
+ Run `agentkit inspect`, `agentkit channels list`, and `agentkit dev`. Configure the provider webhook manually using an HTTPS tunnel to the printed port. Only authenticated webhook routes accept tunnel hosts; the dev UI and other APIs stay loopback-only. Keep the local process running and update registration if the tunnel hostname changes.
10
10
 
11
- ## Commands
12
-
13
- ```sh
14
- agentkit deploy
15
- agentkit channels connect whatsapp main-whatsapp --provider evolution
16
- agentkit channels status main-whatsapp
17
- agentkit channels test main-whatsapp --message "hello"
18
- agentkit channels deliveries list main-whatsapp
19
- agentkit channels buffers list main-whatsapp
20
- ```
21
-
22
- Required secrets:
23
-
24
- ```txt
25
- EVOLUTION_API_BASE_URL
26
- EVOLUTION_API_KEY
27
- EVOLUTION_INSTANCE_NAME
28
- EVOLUTION_WEBHOOK_TOKEN
29
- ```
30
-
31
- If WhatsApp audio transcription is enabled, also set the transcription provider secret declared by `agentkit inspect`, usually `OPENAI_API_KEY` or `GROQ_API_KEY`.
32
-
33
- ## Minimal Working Example
34
-
35
- ```ts
36
- import { defineAgent, whatsappChannel } from "@andreprado/agentkit";
37
-
38
- export default defineAgent({
39
- name: "my-agent",
40
- runtime: "edge",
41
- provider: { name: "test", model: "fake" },
42
- instructions: "./prompts/instructions.md",
43
- secrets: [],
44
- tools: [],
45
- channels: [whatsappChannel({ name: "main-whatsapp", provider: "evolution" })],
46
- access: { mode: "public" },
47
- storage: { driver: "agentkit" },
48
- });
49
- ```
50
-
51
- ## Setup Behavior
52
-
53
- `agentkit channels connect whatsapp main-whatsapp --provider evolution` creates or updates the hosted channel, verifies managed secrets, calls Evolution API `POST /webhook/set/{instance}`, confirms the configured webhook through `GET /webhook/find/{instance}`, then runs a synthetic inbound smoke.
54
-
55
- Expected webhook URL shape:
56
-
57
- ```txt
58
- https://<deploy-host>/channels/main-whatsapp/whatsapp/evolution/webhook
59
- ```
60
-
61
- AgentKit registers the webhook URL with the required token query parameter:
62
-
63
- ```txt
64
- https://<deploy-host>/channels/main-whatsapp/whatsapp/evolution/webhook?token=<EVOLUTION_WEBHOOK_TOKEN>
65
- ```
66
-
67
- `EVOLUTION_API_BASE_URL` must be the public HTTPS origin for the Evolution API server, for example `https://evolution.example.com`. AgentKit rejects HTTP, localhost, private-network, link-local, metadata, and credential-bearing base URLs before sending `EVOLUTION_API_KEY`.
68
-
69
- ## Audio
70
-
71
- Use `transcription` at the agent level and `audio.mode: "transcribe"` on the Evolution channel.
72
-
73
- ```ts
74
- whatsappChannel({
75
- name: "main-whatsapp",
76
- provider: "evolution",
77
- audio: {
78
- mode: "transcribe",
79
- },
80
- })
81
- ```
82
-
83
- Evolution audio webhooks become normalized audio messages. The retryable channel worker downloads media through Evolution API `POST /chat/getBase64FromMediaMessage/{instance}` and sends the bytes to AgentKit's configured transcription provider.
84
-
85
- ## Safety Rules
86
-
87
- - Keep phone numbers redacted in logs by default.
88
- - Do not store Evolution API keys or webhook tokens in `agentkit.config.ts`.
89
- - `EVOLUTION_WEBHOOK_TOKEN` is required because AgentKit V1 does not rely on an Evolution webhook body-signature contract.
90
- - AgentKit ignores `fromMe` messages to avoid reply loops.
91
- - Text replies call Evolution API `POST /message/sendText/{instance}` with the `apikey` header and a body containing `number` and `text`.
92
- - Real provider success is recorded as `provider_sent` only when Evolution returns a provider message id.
93
- - Only set `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` in tests when Evolution should not receive a real message. Dry-run deliveries are recorded as `adapter_stubbed`, not sent.
94
-
95
- ## Verification
96
-
97
- ```sh
98
- agentkit channels setup main-whatsapp --apply
99
- agentkit channels status main-whatsapp
100
- agentkit channels test main-whatsapp --message "hello"
101
- agentkit channels test-audio main-whatsapp --fixture voice-note
102
- agentkit channels deliveries list main-whatsapp
103
- agentkit channels deliveries show <delivery-id>
104
- ```
105
-
106
- ## Troubleshooting
107
-
108
- `channel_secret_missing`:
109
- Set `EVOLUTION_API_BASE_URL`, `EVOLUTION_API_KEY`, `EVOLUTION_INSTANCE_NAME`, and `EVOLUTION_WEBHOOK_TOKEN` as hosted managed secrets.
110
-
111
- `channel_signature_invalid`:
112
- The Evolution webhook query token does not match.
113
-
114
- `channel_provider_setup_invalid`:
115
- `EVOLUTION_API_BASE_URL` is not an allowed public HTTPS base URL.
116
-
117
- `channel_provider_setup_failed`:
118
- AgentKit could not configure or verify the Evolution webhook through `/webhook/set/{instance}` and `/webhook/find/{instance}`.
119
-
120
- `channel_audio_download_unavailable`:
121
- Evolution did not return base64 media data from `/chat/getBase64FromMediaMessage/{instance}`, or the audio payload did not include a provider message id.
11
+ Test with a correctly authenticated fixture and inspect the response, then use `agentkit conversations trace <id>`. A synthetic test does not prove real provider delivery. Use `AGENTKIT_CHANNEL_SEND_DRY_RUN=1` when a test must not send to real recipients. Local buffering is best-effort and in-memory; no durable retry worker is included.