@andreprado/agentkit 0.1.0-alpha.9 → 0.1.1

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 (122) hide show
  1. package/README.md +18 -1
  2. package/docs/guides/add-channel.md +251 -7
  3. package/docs/guides/add-knowledge.md +10 -0
  4. package/docs/guides/add-managed-composio.md +165 -0
  5. package/docs/guides/add-tool.md +10 -3
  6. package/docs/guides/channel-security.md +162 -32
  7. package/docs/guides/connect-discord.md +178 -0
  8. package/docs/guides/connect-slack.md +126 -0
  9. package/docs/guides/connect-telegram.md +61 -1
  10. package/docs/guides/connect-whatsapp-evolution.md +121 -0
  11. package/docs/guides/connect-whatsapp-uazapi.md +139 -0
  12. package/docs/guides/connect-whatsapp-zapster.md +119 -16
  13. package/docs/guides/create-agent.md +31 -4
  14. package/docs/guides/debug-channel.md +159 -0
  15. package/docs/guides/improve-from-production.md +151 -0
  16. package/docs/guides/prepare-deploy.md +32 -14
  17. package/docs/guides/replay-production-traces.md +72 -0
  18. package/docs/guides/run-evals.md +95 -25
  19. package/docs/guides/security-rules.md +9 -5
  20. package/docs/guides/send-feedback.md +135 -0
  21. package/docs/guides/use-jev.md +67 -0
  22. package/docs/guides/use-provider.md +70 -3
  23. package/docs/llms-full.txt +295 -25
  24. package/docs/llms.txt +54 -7
  25. package/package.json +3 -7
  26. package/src/cli/args.ts +23 -2
  27. package/src/cli/cloud-client.ts +121 -9
  28. package/src/cli/commands/channels.ts +856 -36
  29. package/src/cli/commands/feedback.ts +438 -0
  30. package/src/cli/commands/provider.ts +47 -0
  31. package/src/cli/commands/transcribe.ts +171 -0
  32. package/src/cli/deploy-chat-ui.ts +232 -18
  33. package/src/cli/deploy-readiness.ts +227 -14
  34. package/src/cli/help.ts +67 -9
  35. package/src/cli/index.ts +740 -35
  36. package/src/cli/new-command.ts +41 -0
  37. package/src/cloud/client.ts +4 -3
  38. package/src/cloud/contracts.ts +1 -1
  39. package/src/create-project.ts +18 -35
  40. package/src/index.ts +565 -11
  41. package/src/providers/codex-auth.ts +111 -0
  42. package/src/providers/pi.ts +88 -19
  43. package/src/providers/test.ts +36 -0
  44. package/src/providers/types.ts +8 -0
  45. package/src/runtime/channel-test-harness.ts +21 -1
  46. package/src/runtime/channels/discord.ts +904 -0
  47. package/src/runtime/channels/generic-webhook.ts +682 -0
  48. package/src/runtime/channels/net-guard.ts +480 -0
  49. package/src/runtime/channels/provider-fetch.ts +54 -0
  50. package/src/runtime/channels/slack.ts +652 -0
  51. package/src/runtime/channels/telegram.ts +379 -15
  52. package/src/runtime/channels/whatsapp-evolution.ts +1330 -0
  53. package/src/runtime/channels/whatsapp-meta.ts +9 -0
  54. package/src/runtime/channels/whatsapp-uazapi.ts +1192 -0
  55. package/src/runtime/channels/whatsapp-zapster.ts +702 -40
  56. package/src/runtime/channels.ts +83 -3
  57. package/src/runtime/chat.ts +70 -44
  58. package/src/runtime/config.ts +512 -20
  59. package/src/runtime/core/manifest.ts +75 -5
  60. package/src/runtime/core/targets.ts +5 -5
  61. package/src/runtime/deploy-readiness.ts +34 -4
  62. package/src/runtime/dev-server.ts +639 -39
  63. package/src/runtime/env.ts +8 -3
  64. package/src/runtime/evals.ts +445 -74
  65. package/src/runtime/improve.ts +868 -0
  66. package/src/runtime/inspect.ts +173 -4
  67. package/src/runtime/integrations/composio.ts +425 -0
  68. package/src/runtime/knowledge/embeddings.ts +45 -7
  69. package/src/runtime/knowledge/ingest.ts +69 -6
  70. package/src/runtime/knowledge/retrieve.ts +25 -5
  71. package/src/runtime/knowledge/schema.ts +45 -1
  72. package/src/runtime/knowledge/vector.ts +30 -30
  73. package/src/runtime/prompt-context.ts +141 -0
  74. package/src/runtime/runtime-contract.ts +71 -7
  75. package/src/runtime/skills.ts +95 -0
  76. package/src/runtime/targets/cloudflare/build.ts +1010 -208
  77. package/src/runtime/targets/container/server.ts +1 -1
  78. package/src/runtime/targets/vps/deploy.ts +26 -9
  79. package/src/runtime/tool-runner.ts +9 -1
  80. package/src/runtime/tools.ts +26 -2
  81. package/src/runtime/transcription.ts +483 -0
  82. package/src/storage/sqlite.ts +7 -2
  83. package/src/templates/blank.ts +37 -9
  84. package/src/templates/dentista.ts +40 -14
  85. package/src/templates/skills/agentkit-build-agent/SKILL.md +34 -5
  86. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +2 -1
  87. package/src/templates/skills/agentkit-capsule/SKILL.md +32 -3
  88. package/src/templates/skills/agentkit-capsule/references/docs-router.md +2 -2
  89. package/src/templates/skills/agentkit-channels/SKILL.md +66 -1
  90. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +8 -1
  91. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +28 -3
  92. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  93. package/src/templates/skills/agentkit-channels/references/slack.md +56 -0
  94. package/src/templates/skills/agentkit-channels/references/telegram.md +34 -0
  95. package/src/templates/skills/agentkit-channels/references/whatsapp-evolution.md +57 -0
  96. package/src/templates/skills/agentkit-channels/references/whatsapp-uazapi.md +54 -0
  97. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +42 -8
  98. package/src/templates/skills/agentkit-database/SKILL.md +11 -0
  99. package/src/templates/skills/agentkit-deploy/SKILL.md +9 -1
  100. package/src/templates/skills/agentkit-evals/SKILL.md +77 -13
  101. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +13 -6
  102. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +8 -4
  103. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +8 -4
  104. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +16 -7
  105. package/src/templates/skills/agentkit-improve/SKILL.md +96 -0
  106. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  107. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  108. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  109. package/src/templates/skills/agentkit-integrations/SKILL.md +98 -0
  110. package/src/templates/skills/agentkit-knowledge/SKILL.md +4 -1
  111. package/src/templates/skills/agentkit-prompts/SKILL.md +3 -1
  112. package/src/templates/skills/agentkit-provider/SKILL.md +29 -4
  113. package/src/templates/skills/agentkit-security/SKILL.md +5 -2
  114. package/src/templates/skills/agentkit-tools/SKILL.md +8 -1
  115. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +8 -8
  116. package/src/templates/skills/agentkit-tools/examples/jev-service-fit.tool.md +110 -0
  117. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +25 -1
  118. package/src/templates/support.ts +42 -12
  119. package/docs/guides/agentkit-skills-architecture.md +0 -471
  120. package/docs/guides/channels-implementation-map.md +0 -243
  121. package/docs/guides/channels-production-handoff.md +0 -101
  122. package/docs/portable-deploy-release-checklist.md +0 -41
@@ -64,6 +64,7 @@ node_modules/
64
64
  OPENAI_API_KEY=
65
65
  ANTHROPIC_API_KEY=
66
66
  OPENROUTER_API_KEY=
67
+ OPENCODE_API_KEY=
67
68
  `,
68
69
  },
69
70
  {
@@ -83,6 +84,7 @@ export default defineAgent({
83
84
  name: "test",
84
85
  model: "fake",
85
86
  },
87
+ timeZone: "America/Sao_Paulo",
86
88
  instructions: "./prompts/instructions.md",
87
89
  secrets: [],
88
90
  tools: [listarHorariosDisponiveis, consultarConsulta, agendarConsulta, alterarConsulta],
@@ -282,7 +284,7 @@ export const listarHorariosDisponiveis = defineTool<ListarHorariosInput, { data:
282
284
  },
283
285
  async execute(input, ctx) {
284
286
  const date = normalizeDate(input.data);
285
- const dateError = validateAppointmentDate(date);
287
+ const dateError = validateAppointmentDate(date, ctx.clock.now);
286
288
 
287
289
  if (dateError) {
288
290
  return {
@@ -409,6 +411,7 @@ export const agendarConsulta = defineTool<AgendarConsultaInput, AgendaOutput>({
409
411
  data,
410
412
  horario,
411
413
  confirmadoPeloCliente: input.confirmadoPeloCliente,
414
+ now: ctx.clock.now,
412
415
  });
413
416
 
414
417
  if (!validation.ok) {
@@ -482,6 +485,7 @@ export const alterarConsulta = defineTool<AlterarConsultaInput, AgendaOutput>({
482
485
  data,
483
486
  horario,
484
487
  confirmadoPeloCliente: input.confirmadoPeloCliente,
488
+ now: ctx.clock.now,
485
489
  });
486
490
 
487
491
  if (!contact.ok) {
@@ -575,9 +579,9 @@ export const alterarConsulta = defineTool<AlterarConsultaInput, AgendaOutput>({
575
579
 
576
580
  async function validateScheduleRequest(
577
581
  db: DatabaseRunner,
578
- input: { data: string; horario: string; confirmadoPeloCliente: boolean },
582
+ input: { data: string; horario: string; confirmadoPeloCliente: boolean; now: Date },
579
583
  ): Promise<{ ok: boolean; mensagem: string; disponiveis: string[] }> {
580
- const dateError = validateAppointmentDate(input.data);
584
+ const dateError = validateAppointmentDate(input.data, input.now);
581
585
 
582
586
  if (dateError) {
583
587
  return {
@@ -698,7 +702,7 @@ function normalizeTime(input: string): string {
698
702
  return \`\${match[1].padStart(2, "0")}:\${match[2]}\`;
699
703
  }
700
704
 
701
- function validateAppointmentDate(data: string): string | null {
705
+ function validateAppointmentDate(data: string, now: Date): string | null {
702
706
  if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(data)) {
703
707
  return "Use a data no formato YYYY-MM-DD.";
704
708
  }
@@ -710,20 +714,20 @@ function validateAppointmentDate(data: string): string | null {
710
714
  return "Esta data nao existe. Confirme a data com o cliente.";
711
715
  }
712
716
 
713
- if (data < todayInClinicTimezone()) {
717
+ if (data < todayInClinicTimezone(now)) {
714
718
  return "Nao agende consultas em datas passadas.";
715
719
  }
716
720
 
717
721
  return null;
718
722
  }
719
723
 
720
- function todayInClinicTimezone(): string {
724
+ function todayInClinicTimezone(now: Date): string {
721
725
  const parts = new Intl.DateTimeFormat("en-US", {
722
726
  timeZone: CLINIC_TIME_ZONE,
723
727
  year: "numeric",
724
728
  month: "2-digit",
725
729
  day: "2-digit",
726
- }).formatToParts(new Date());
730
+ }).formatToParts(now);
727
731
  const byType = Object.fromEntries(parts.map((part) => [part.type, part.value]));
728
732
  return \`\${byType.year}-\${byType.month}-\${byType.day}\`;
729
733
  }
@@ -838,13 +842,18 @@ Quando o cliente quiser alterar a própria consulta:
838
842
  },
839
843
  {
840
844
  path: "evals/smoke.eval.ts",
841
- contents: `export default {
845
+ contents: `import { defineEval } from "@andreprado/agentkit";
846
+
847
+ export default defineEval({
842
848
  name: "smoke",
843
849
  input: "Oi, quero marcar uma consulta.",
844
850
  expect: {
845
- contains: "nome",
851
+ response: {
852
+ containsAny: ["nome", "Nome"],
853
+ notRegex: ["API_KEY|secret|token"],
854
+ },
846
855
  },
847
- };
856
+ });
848
857
  `,
849
858
  },
850
859
  {
@@ -857,7 +866,21 @@ Esta é uma AgentKit Agent Capsule para a Clara, atendente em português de um c
857
866
 
858
867
  A Clara conversa com clientes, coleta nome, email e telefone, consulta disponibilidade e agenda consultas em slots de 30 minutos. Ela também consulta e altera o próprio horário do cliente usando email e telefone como verificação mínima.
859
868
 
860
- Quando o dono pedir mudanças em linguagem natural, crie ou atualize \`AGENT_SPEC.md\` com \`npm run agentkit -- spec init --brief "<pedido do dono>"\`. O dono dá a ideia geral; o agente de código transforma isso no contrato estruturado.
869
+ Quando o dono pedir mudanças em linguagem natural, trate a mensagem como o brief. O dono não deve precisar rodar wizard ou preparar arquivo de brief. Crie ou atualize \`AGENT_SPEC.md\` com \`npm run agentkit -- spec init --brief "<pedido do dono>"\`; o agente de código transforma a ideia geral no contrato estruturado.
870
+
871
+ ## Contrato Proativo De Produto Testável
872
+
873
+ Não edite apenas o prompt. Para cada requisito relevante do pedido ou do \`AGENT_SPEC.md\`, decida qual artefato deve garantir o comportamento:
874
+
875
+ - entrada no spec para o contrato de produto;
876
+ - instrução no prompt para comportamento, tom, limites, coleta de dados e escalonamento;
877
+ - ferramenta mais registro no config para ações, dados vivos, escritas externas ou dados sensíveis;
878
+ - schema/migration mais ferramenta para dados duráveis;
879
+ - eval para privacidade, confirmação, campos obrigatórios, horário comercial, datas, duração e regressões;
880
+ - fixture, seed, branch fake ou teste direto de ferramenta para integrações e caminhos de erro;
881
+ - checagem de deploy/readiness para secrets hosted, canais, integrações ou acesso de produção.
882
+
883
+ Regras que protegem privacidade, agendamento, confirmação, dados de cliente, horário comercial ou segurança precisam de eval ou checagem determinística antes de dizer que a cápsula está pronta. Se uma conversa real revelar bug, transforme em uma eval de regressão pequena antes ou junto da correção.
861
884
 
862
885
  ## Regras de Produto
863
886
 
@@ -900,16 +923,19 @@ Quando o dono pedir mudanças em linguagem natural, crie ou atualize \`AGENT_SPE
900
923
  - UI local: rode \`npm run dev\`, abra a URL impressa em \`Chat:\` e informe essa URL exata ao dono.
901
924
  - UI pós-deploy: depois de \`npm run agentkit -- deploy\`, rode \`npm run agentkit -- chat-ui --deploy\`, abra a URL impressa em \`Chat:\` e informe que ela está conectada ao deploy hospedado.
902
925
  - \`test/fake\` é determinístico. Ele valida scaffold, ferramentas e evals previsíveis, mas não valida qualidade de conversa natural.
903
- - Antes de dizer que a conversa real foi testada, pergunte ao dono qual provider usar: OpenRouter, OpenAI, Anthropic ou outro provider suportado. Não escolha pelo dono.
926
+ - Antes de dizer que a conversa real foi testada, pergunte ao dono qual provider usar: OpenRouter, OpenAI, Anthropic, OpenCode Zen, OpenCode Go ou outro provider suportado. Não escolha pelo dono.
904
927
 
905
928
  ## Regras de Implementação
906
929
 
907
930
  - Use \`ctx.db\` nas ferramentas. Não importe drivers SQLite, Turso ou Node-only APIs.
908
931
  - Mantenha \`schema.sql\` idempotente com \`CREATE TABLE IF NOT EXISTS\` e \`CREATE INDEX IF NOT EXISTS\`. Use \`migrations/*.sql\` ordenadas para evolução de schema com cara de produção.
932
+ - Quando a mudança exigir persistência nova, implemente a fatia completa: schema/migration, ferramenta, registro no config, instruções no prompt, teste direto da ferramenta e eval.
909
933
  - Use \`npm run agentkit -- sync init\` quando a agente depender de catálogo externo, fixture local ou seed padronizado.
934
+ - Para regras de privacidade, confirmação, campos obrigatórios, timezone, horário comercial, duração, erro de integração ou no-leak, adicione uma eval, fixture, branch fake ou teste direto de ferramenta.
935
+ - Transforme conversas reais com falhas em regressão com \`npm run agentkit -- eval from-conversation <conversation-id>\`.
910
936
  - Mantenha segredos em \`.env\`, nunca em arquivos versionados.
911
937
  - Não espere wizard ou recipe. AgentKit fornece o scaffold e o contrato; implemente diretamente conforme o brief do dono.
912
- - Para trocar para um provider real, o dono deve escolher OpenRouter, OpenAI, Anthropic ou outro provider suportado. Depois edite \`agentkit.config.ts\`, atualize \`.env.schema\` e configure secrets locais/hosted.
938
+ - Para trocar para um provider real, o dono deve escolher OpenRouter, OpenAI, Anthropic, OpenCode Zen, OpenCode Go ou outro provider suportado. Depois edite \`agentkit.config.ts\`, atualize \`.env.schema\` e configure secrets locais/hosted.
913
939
  - Quando a próxima ação não for óbvia, comece por \`skills/agentkit-capsule/SKILL.md\`.
914
940
  `,
915
941
  },
@@ -987,7 +1013,7 @@ npm run agentkit -- chat-ui --deploy
987
1013
 
988
1014
  Abra a URL impressa em \`Chat:\` e informe que essa UI local está conectada ao deploy hospedado.
989
1015
 
990
- Antes de dizer que a conversa real foi testada, pergunte ao dono qual provider usar: OpenRouter, OpenAI, Anthropic ou outro provider suportado. Não escolha pelo dono. Depois configure \`agentkit.config.ts\`, \`.env.schema\`, secrets locais e secrets hosted se for deployar.
1016
+ Antes de dizer que a conversa real foi testada, pergunte ao dono qual provider usar: OpenRouter, OpenAI, Anthropic, OpenCode Zen, OpenCode Go ou outro provider suportado. Não escolha pelo dono. Depois configure \`agentkit.config.ts\`, \`.env.schema\`, secrets locais e secrets hosted se for deployar.
991
1017
 
992
1018
  ## Deploy
993
1019
 
@@ -7,17 +7,46 @@ description: Use when the owner gives a natural-language brief for a new or chan
7
7
 
8
8
  Use this when the owner asks for an agent in plain language.
9
9
 
10
+ The owner should only need to run `agentkit new [name]` or `agentkit new .`, open the capsule in Codex or another coding agent, and say what agent they want. Do not send them back to the CLI for a brief wizard. Treat their chat message as the brief and build the first useful local capsule.
11
+
10
12
  ## Workflow
11
13
 
12
14
  1. Read `agentkit.config.ts`, `prompts/instructions.md`, `schema.sql`, `evals/`, and existing `tools/`.
13
15
  2. If `AGENT_SPEC.md` does not exist, create it from the owner's plain-language request with `npm run agentkit -- spec init --brief "<owner request>"`. If it exists, update it directly before changing behavior.
14
16
  3. Infer the first useful local version from the owner's brief and the spec. Do not ask the owner to fill a form.
15
17
  4. Edit `prompts/instructions.md` for behavior, boundaries, intake questions, escalation rules, and tool-use policy.
16
- 5. Add tools only when the agent needs action, live data, authorization-sensitive data, or durable writes.
17
- 6. Add database tables to `schema.sql` or ordered `migrations/*.sql` when the agent owns records.
18
- 7. Add `sync.ts` and `seed.sql` with `npm run agentkit -- sync init` when the agent depends on external catalogs or recurring imports.
19
- 8. Add or update evals for the main flow. Prefer multi-turn `turns` evals for real conversations.
20
- 9. Keep the capsule runnable on `test/fake` unless the owner has chosen a real provider.
18
+ 5. For scheduling, deadlines, reminders, or any relative-date behavior, set `timeZone` in `agentkit.config.ts` to the business/user timezone. AgentKit injects the current date, weekday, timestamp, and timezone dynamically at runtime; do not hardcode today's date in prompts.
19
+ 6. Add tools when the agent needs action, live data, authorization-sensitive data, durable writes, or a requested external judgment such as TypeSafe/Jev. Use `skills/agentkit-tools/SKILL.md` for the tool workflow and Jev guidance.
20
+ 7. Add database tables to `schema.sql` or ordered `migrations/*.sql` when the agent owns records.
21
+ 8. Add `sync.ts` and `seed.sql` with `npm run agentkit -- sync init` when the agent depends on external catalogs or recurring imports.
22
+ 9. Turn requirements into checks as you build. Every privacy rule, external write, confirmation step, business-hour rule, timezone rule, required intake field, and customer-data boundary needs an eval, direct tool check, fixture, or deterministic fake path.
23
+ 10. Add or update evals for the main flow. Prefer multi-turn `turns` evals for real conversations.
24
+ 11. Keep the capsule runnable on `test/fake` unless the owner has chosen a real provider.
25
+
26
+ ## Requirement-To-Verification Loop
27
+
28
+ For each item in the brief or `AGENT_SPEC.md`, classify it before finishing:
29
+
30
+ - prompt-only behavior: add a prompt instruction and a response eval when the wording or boundary matters;
31
+ - required intake such as name, phone, email, budget, or account id: add a multi-turn eval that proves the agent asks before acting;
32
+ - tool call or external write: add a persisted tool-call eval and a direct `agentkit tool` check;
33
+ - database record: implement the complete slice in the next section;
34
+ - scheduling, deadlines, or timezone: set `timeZone`, freeze eval `now`, and assert the date/time sent to tools;
35
+ - privacy/no-leak rule: add a no-leak eval with `notContains` or `notRegex`;
36
+ - integration failure such as rate limit, timeout, unavailable slot, or missing auth: add a fixture, fake branch, or eval-safe tool behavior.
37
+
38
+ If a requirement is important enough to mention in the spec, it is usually important enough to test. State any untested requirement in the final response.
39
+
40
+ ## Complete Slice
41
+
42
+ When the brief implies durable records such as leads, clients, bookings, tickets, or notes, do the whole local slice:
43
+
44
+ - add or update `schema.sql` and ordered `migrations/*.sql` when appropriate;
45
+ - add the `defineTool` implementation under `tools/`;
46
+ - register the tool in `agentkit.config.ts`;
47
+ - teach `prompts/instructions.md` when and how to use the tool;
48
+ - add a direct tool check fixture or command;
49
+ - add an eval that proves the agent calls the tool in the expected flow.
21
50
 
22
51
  ## Templates
23
52
 
@@ -13,8 +13,9 @@ Required intake:
13
13
  - Any urgency or special constraints
14
14
 
15
15
  Rules:
16
+ - Interpret today, tomorrow, weekdays, and vague time windows using the AgentKit runtime date context.
17
+ - If the user's scheduling timezone may differ from the business timezone, confirm the timezone before booking.
16
18
  - Do not diagnose, promise outcomes, or provide emergency guidance beyond directing urgent cases to appropriate human or emergency support.
17
19
  - Do not create, change, or cancel an appointment without explicit user confirmation.
18
20
  - Do not invent availability.
19
21
  - Use the scheduling tools for availability and writes.
20
-
@@ -7,6 +7,27 @@ description: Use when working inside an AgentKit Agent Capsule, especially after
7
7
 
8
8
  Use this first inside an AgentKit Agent Capsule.
9
9
 
10
+ ## Owner-To-Codex Contract
11
+
12
+ The owner has already done the setup work by running `agentkit new [name]` or `agentkit new .` and opening this folder in a coding agent. When they ask for an agent in natural language, that message is the brief.
13
+
14
+ - Do not ask the owner to run a wizard, fill a form, or prepare `AGENT_SPEC.md`.
15
+ - Route immediately to `skills/agentkit-build-agent/SKILL.md`.
16
+ - You create or update `AGENT_SPEC.md`, prompts, tools, schema, evals, and docs as needed.
17
+ - Use the CLI for validation and deployment, not for business inference.
18
+
19
+ ## Proactive Builder Contract
20
+
21
+ Do not stop at "the prompt was edited." For every meaningful requirement in the owner's brief or `AGENT_SPEC.md`, decide which artifact must enforce it:
22
+
23
+ - behavior or tone: `prompts/instructions.md`;
24
+ - action, live data, or external write: `tools/` plus `agentkit.config.ts`;
25
+ - durable records: schema/migration, tool, config registration, prompt guidance, direct tool check, and eval;
26
+ - privacy, confirmation, business hours, dates, money, safety, or client data: at least one eval or deterministic check;
27
+ - production or integration dependency: deploy/readiness check and safe fixture or fake path.
28
+
29
+ If a real conversation reveals a bug or risky behavior, convert it into a regression eval before or alongside the fix.
30
+
10
31
  ## Start
11
32
 
12
33
  1. Treat the directory containing `agentkit.config.ts` as the capsule root.
@@ -18,14 +39,16 @@ Use this first inside an AgentKit Agent Capsule.
18
39
 
19
40
  - Build or reshape the agent from the owner's brief: `skills/agentkit-build-agent/SKILL.md`
20
41
  - Edit prompts: `skills/agentkit-prompts/SKILL.md`
21
- - Add actions or external data: `skills/agentkit-tools/SKILL.md`
42
+ - Add actions, external data, or TypeSafe/Jev judgments: `skills/agentkit-tools/SKILL.md`
43
+ - Add AgentKit-managed integrations such as managed Composio: `skills/agentkit-integrations/SKILL.md`
22
44
  - Add database tables or database-backed tools: `skills/agentkit-database/SKILL.md`
23
45
  - Add docs, FAQs, prices, policies, or CSV facts: `skills/agentkit-knowledge/SKILL.md`
24
46
  - Switch from `test/fake` to a real model provider: `skills/agentkit-provider/SKILL.md`
25
47
  - Add or run evals: `skills/agentkit-evals/SKILL.md`
48
+ - Improve from hosted or local production evidence: `skills/agentkit-improve/SKILL.md`
26
49
  - Prepare hosted deploy: `skills/agentkit-deploy/SKILL.md`
27
50
  - Work with secrets, external APIs, public access, channels, or real data: `skills/agentkit-security/SKILL.md`
28
- - Add or debug website, Telegram, or WhatsApp channels: `skills/agentkit-channels/SKILL.md`
51
+ - Add or debug website, Telegram, WhatsApp, Discord, Slack, or generic webhook channels: `skills/agentkit-channels/SKILL.md`
29
52
  - Investigate command failures: `skills/agentkit-troubleshooting/SKILL.md`
30
53
 
31
54
  For a compact docs map, read `references/docs-router.md`.
@@ -52,11 +75,17 @@ If you change behavior, add or update an eval and run:
52
75
  npm run eval
53
76
  ```
54
77
 
78
+ If the change fixes production behavior, also collect or use an improve bundle and run:
79
+
80
+ ```sh
81
+ npm run agentkit -- replay .agentkit/improve/<run> --against local
82
+ ```
83
+
55
84
  ## Rules
56
85
 
57
86
  - Keep `.env`, `.agentkit/`, and `node_modules/` out of commits.
58
87
  - Keep secret names in `.env.schema`; keep secret values in ignored `.env` or hosted managed secrets.
59
88
  - Keep the first useful version runnable with `test/fake` unless the owner explicitly chooses a real provider.
89
+ - For scheduling or relative-date agents, set `timeZone` in `agentkit.config.ts`; AgentKit injects the current date, weekday, timestamp, and timezone dynamically at runtime.
60
90
  - Ask follow-up questions only when missing information blocks a safe local implementation.
61
91
  - Tell the owner when testing used `test/fake` instead of a real provider.
62
-
@@ -6,10 +6,10 @@ Prefer the narrowest source that covers the task.
6
6
  - Tools, schemas, secrets, and direct tool tests: `docs/guides/add-tool.md`
7
7
  - Knowledge sources, indexing, search, and hosted sync: `docs/guides/add-knowledge.md`
8
8
  - Evals and deterministic side-effect guards: `docs/guides/run-evals.md`
9
+ - Safe AgentKit product feedback drafts/submission: `docs/guides/send-feedback.md`
9
10
  - Real provider setup: `docs/guides/use-provider.md`
10
11
  - Deploy readiness, managed secrets, smoke checks, hosted UI: `docs/guides/prepare-deploy.md`
11
- - Channels: `docs/guides/add-channel.md`, `connect-telegram.md`, `connect-whatsapp-zapster.md`, `debug-channel.md`
12
+ - Channels: `docs/guides/add-channel.md`, `connect-discord.md`, `connect-slack.md`, `connect-telegram.md`, `connect-whatsapp-evolution.md`, `connect-whatsapp-uazapi.md`, `connect-whatsapp-zapster.md`, `debug-channel.md`
12
13
  - Security: `docs/guides/security-rules.md`
13
14
 
14
15
  Use `npm run agentkit -- docs full` only for a complete-contract audit, framework internals, or a behavior not covered by the task guide.
15
-
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: agentkit-channels
3
- description: Use when adding, connecting, testing, buffering, or debugging AgentKit website, Telegram, or WhatsApp channels, including channel config helpers, provider secrets, webhook setup, channel tests, delivery logs, and burst-message buffers.
3
+ description: Use when adding, connecting, testing, buffering, transcribing audio, or debugging AgentKit website, Telegram, WhatsApp, Discord, Slack, or generic webhook channels, including channel config helpers, provider secrets, webhook setup, channel tests, delivery logs, burst-message buffers, and transcription provider secrets.
4
4
  ---
5
5
 
6
6
  # AgentKit Channels
@@ -16,6 +16,41 @@ Channels receive user messages. Tools let the agent call external systems. Keep
16
16
  5. Connect channel resources through the CLI.
17
17
  6. Test, doctor, and inspect delivery logs.
18
18
 
19
+ ## Audio Transcription
20
+
21
+ Enable transcription at the agent level and opt in per channel with `audio.mode: "transcribe"`.
22
+
23
+ ```ts
24
+ export default defineAgent({
25
+ // ...
26
+ transcription: {
27
+ provider: "groq",
28
+ model: "whisper-large-v3-turbo",
29
+ secret: "GROQ_API_KEY",
30
+ language: "pt",
31
+ limits: {
32
+ maxDurationSeconds: 180,
33
+ maxBytes: 20_000_000,
34
+ },
35
+ },
36
+ channels: [
37
+ telegramChannel({
38
+ name: "support-telegram",
39
+ audio: { mode: "transcribe" },
40
+ }),
41
+ ],
42
+ });
43
+ ```
44
+
45
+ V1 providers:
46
+
47
+ - `openai`: `gpt-4o-mini-transcribe`, `gpt-4o-transcribe`, `whisper-1`; default secret `OPENAI_API_KEY`.
48
+ - `groq`: `whisper-large-v3-turbo`, `whisper-large-v3`, `distil-whisper-large-v3-en`; default secret `GROQ_API_KEY`.
49
+
50
+ Telegram voice notes are usually OGG/Opus, so use Groq for the default Telegram voice-note path in V1. Zapster audio needs a usable HTTPS Zapster media download URL in the webhook payload; arbitrary hosts are rejected before bearer auth is sent. UAZAPI audio downloads go through UAZAPI `/message/download` with base64 return enabled. Evolution audio downloads go through Evolution API `/chat/getBase64FromMediaMessage/{instance}` with base64 return enabled. Arbitrary UAZAPI and Evolution webhook media hosts are not fetched. Hosted channel creation requires the transcription secret automatically when the channel enables transcription. Webhooks only enqueue audio jobs; download and transcription run in the retryable channel worker before the agent run.
51
+
52
+ Discord channels do not support audio in V1.
53
+
19
54
  ## Buffering
20
55
 
21
56
  Enable `buffer.mode: "debounce"` when clients send several short messages in a row and the agent should answer once.
@@ -45,14 +80,26 @@ npm run agentkit -- channels list
45
80
  npm run agentkit -- channels add website website-chat
46
81
  npm run agentkit -- channels connect telegram support-telegram
47
82
  npm run agentkit -- channels add whatsapp support-whatsapp --provider zapster
83
+ npm run agentkit -- channels connect whatsapp support-whatsapp --provider uazapi
84
+ npm run agentkit -- channels connect whatsapp main-whatsapp --provider evolution
85
+ npm run agentkit -- channels connect discord support-discord
86
+ npm run agentkit -- channels connect discord server-discord --mode bot
87
+ npm run agentkit -- channels connect slack support-slack
88
+ npm run agentkit -- channels connect webhook n8n-webhook
48
89
  npm run agentkit -- channels doctor support-telegram
49
90
  npm run agentkit -- channels test support-telegram --message "hello"
91
+ npm run agentkit -- channels test-audio support-telegram --fixture voice-note
92
+ npm run agentkit -- transcribe smoke --provider groq
50
93
  npm run agentkit -- channels deliveries list support-telegram
51
94
  ```
52
95
 
53
96
  ## References
54
97
 
98
+ - `references/discord.md`
99
+ - `references/slack.md`
55
100
  - `references/telegram.md`
101
+ - `references/whatsapp-evolution.md`
102
+ - `references/whatsapp-uazapi.md`
56
103
  - `references/whatsapp-zapster.md`
57
104
  - `references/channel-buffering.md`
58
105
  - `references/channel-debugging.md`
@@ -60,3 +107,21 @@ npm run agentkit -- channels deliveries list support-telegram
60
107
  ## Safety
61
108
 
62
109
  Do not paste provider tokens into code, docs, fixtures, prompts, evals, or delivery logs. Webhook URLs are public transport endpoints; authenticity comes from provider validation or channel tokens.
110
+
111
+ ## Generic Webhooks
112
+
113
+ Use `webhookChannel({ name: "n8n-webhook" })` for n8n, Make, Zapier, Pipedream, or custom server events.
114
+
115
+ Canonical JSON:
116
+
117
+ ```json
118
+ {
119
+ "event_id": "evt_123",
120
+ "external_id": "customer_123",
121
+ "message": "hello from n8n"
122
+ }
123
+ ```
124
+
125
+ `event_id` is required for dedupe. `external_id` is recommended for conversation continuity and is hashed before storage. Authenticate with `Authorization: Bearer <AGENTKIT_WEBHOOK_SECRET>`, `X-AgentKit-Webhook-Secret`, or `X-AgentKit-Webhook-Signature: sha256=<hmac of raw JSON body>`.
126
+
127
+ Generic webhooks are inbound-only in V1. Add a separate tool if the agent must call back into n8n after it runs.
@@ -43,6 +43,11 @@ Behavior:
43
43
  Debug:
44
44
 
45
45
  ```sh
46
+ agentkit channels buffers list <name>
47
+ agentkit channels buffers show <conversation-id>
48
+ agentkit channels buffers flush <conversation-id>
49
+ agentkit channels buffers clear <conversation-id>
50
+ agentkit channels buffers retry <conversation-id>
46
51
  agentkit channels deliveries list <name>
47
52
  agentkit channels deliveries show <delivery-id>
48
53
  ```
@@ -54,5 +59,7 @@ buffered
54
59
  queued
55
60
  running
56
61
  agent_completed
57
- outbound_sent
62
+ provider_request_built
63
+ provider_sent
64
+ adapter_stubbed
58
65
  ```
@@ -7,8 +7,15 @@ agentkit channels list
7
7
  agentkit channels status <name>
8
8
  agentkit channels doctor <name>
9
9
  agentkit channels test <name> --message "hello"
10
+ agentkit channels test-audio <name> --fixture voice-note
11
+ agentkit transcribe smoke --provider groq
10
12
  agentkit channels deliveries list <name> --since 24h
11
13
  agentkit channels deliveries show <delivery-id>
14
+ agentkit channels buffers list <name>
15
+ agentkit channels buffers show <conversation-id>
16
+ agentkit channels buffers flush <conversation-id>
17
+ agentkit channels buffers clear <conversation-id>
18
+ agentkit channels buffers retry <conversation-id>
12
19
  ```
13
20
 
14
21
  Common states:
@@ -17,11 +24,17 @@ Common states:
17
24
  webhook_received
18
25
  validated
19
26
  duplicate
27
+ audio_received
28
+ audio_downloaded
29
+ transcribing
30
+ transcribed
20
31
  buffered
21
32
  queued
22
33
  running
23
34
  agent_completed
24
- outbound_sent
35
+ provider_request_built
36
+ provider_sent
37
+ adapter_stubbed
25
38
  delivered
26
39
  provider_failed
27
40
  synthetic_expected_failure
@@ -31,11 +44,23 @@ skipped
31
44
 
32
45
  Common errors:
33
46
 
34
- - `channel_not_found`: webhook URL points to an unknown channel.
47
+ - `channel_not_found`: webhook URL points to an unknown channel. `channels test` is the official synthetic smoke and should resolve the current `.agentkit/deploy.json` channel.
35
48
  - `channel_secret_missing`: required hosted secret is not set.
36
- - `channel_signature_invalid`: webhook secret/token mismatch.
49
+ - `channel_signature_invalid`: webhook secret, token, origin header, or Discord public key mismatch.
50
+ - Discord bot mode with no deliveries: confirm `--mode bot`, `DISCORD_BOT_TOKEN`, Message Content Intent, server install, and channel permissions for View Channel, Read Message History, and Send Messages.
37
51
  - `channel_payload_invalid`: malformed or unsupported provider payload.
38
52
  - `channel_event_duplicate`: provider retry; do not create a second run.
53
+ - `audio_received`: audio message was accepted and normalized.
54
+ - `audio_downloaded`: retryable channel worker downloaded provider media into memory.
55
+ - `transcribing`: AgentKit is calling the configured transcription provider.
56
+ - `transcribed`: transcript text was queued for the agent.
57
+ - `channel_audio_download_unavailable`: provider audio payload did not include a usable download URL, or Zapster sent a non-HTTPS/non-Zapster media host.
58
+ - `transcription_secret_missing`: managed transcription secret is missing.
59
+ - `transcription_audio_too_large` or `transcription_audio_too_long`: audio exceeded configured limits.
60
+ - `transcription_audio_format_unsupported`: provider does not accept this audio MIME type or extension.
61
+ - `transcription_provider_unavailable`: retryable transcription provider failure.
39
62
  - `channel_limit_exceeded`: backpressure skipped the message.
40
63
  - `synthetic_expected_failure`: a synthetic test reached AgentKit, but the provider correctly rejected a fake test recipient.
41
64
  - `buffered` delivery state: message is waiting for the channel quiet window or max wait before one coalesced agent run is queued.
65
+ - `adapter_stubbed`: adapter completed without calling an outbound provider, either because explicit dry-run mode is enabled or the channel is inbound-only.
66
+ - `provider_sent`: the provider accepted the outbound send and returned a provider message ID.
@@ -0,0 +1,93 @@
1
+ # Discord Channel
2
+
3
+ Discord supports two modes:
4
+
5
+ - `interactions`: slash commands through the Discord Interactions Endpoint URL.
6
+ - `bot`: normal server messages through a Discord Bot user and Gateway connection.
7
+
8
+ Use bot mode when the owner asks for the agent to answer without slash commands.
9
+
10
+ ## Slash Commands
11
+
12
+ Required secret:
13
+
14
+ ```txt
15
+ DISCORD_PUBLIC_KEY
16
+ ```
17
+
18
+ Config:
19
+
20
+ ```ts
21
+ discordChannel({ name: "support-discord" })
22
+ ```
23
+
24
+ Commands:
25
+
26
+ ```sh
27
+ agentkit deploy
28
+ agentkit secret set DISCORD_PUBLIC_KEY --stdin
29
+ agentkit channels connect discord support-discord
30
+ agentkit channels test support-discord --message "hello"
31
+ agentkit channels deliveries list support-discord
32
+ ```
33
+
34
+ Paste the printed webhook URL into the application's Interactions Endpoint URL. Register a slash command with a string option named `message`, `text`, `prompt`, `question`, `query`, or `input`.
35
+
36
+ ## Bot Server Messages
37
+
38
+ Required secret:
39
+
40
+ ```txt
41
+ DISCORD_BOT_TOKEN
42
+ ```
43
+
44
+ Config:
45
+
46
+ ```ts
47
+ discordChannel({
48
+ name: "server-discord",
49
+ mode: "bot",
50
+ })
51
+ ```
52
+
53
+ Commands:
54
+
55
+ ```sh
56
+ agentkit deploy
57
+ agentkit secret set DISCORD_BOT_TOKEN --stdin
58
+ agentkit channels connect discord server-discord --mode bot
59
+ agentkit channels test server-discord --message "hello"
60
+ agentkit channels deliveries list server-discord
61
+ ```
62
+
63
+ In the Discord Developer Portal, open the Bot page, enable Message Content Intent, install the app into the server, and grant the bot `View Channel`, `Read Message History`, and `Send Messages` in the channels it should answer.
64
+
65
+ Bot mode processes every readable non-bot text message Discord sends over the Gateway. Keep server permissions narrow if the agent should answer only in specific channels.
66
+
67
+ ## Buffering
68
+
69
+ Buffer rapid Discord messages:
70
+
71
+ ```ts
72
+ discordChannel({
73
+ name: "server-discord",
74
+ mode: "bot",
75
+ buffer: {
76
+ mode: "debounce",
77
+ quietWindowMs: 1500,
78
+ maxWaitMs: 8000,
79
+ maxMessages: 20,
80
+ maxChars: 8000,
81
+ },
82
+ })
83
+ ```
84
+
85
+ ## Runtime Behavior
86
+
87
+ Slash-command mode validates `X-Signature-Ed25519` and `X-Signature-Timestamp` against the raw body and `DISCORD_PUBLIC_KEY`, returns `type: 1` for Discord `PING`, acknowledges slash commands with a deferred response, then sends the final answer as an interaction follow-up.
88
+
89
+ Bot mode connects to Discord Gateway with `DISCORD_BOT_TOKEN`, requests guild message and message-content intents, ignores bot-authored messages, normalizes `MESSAGE_CREATE`, and sends the final answer through `/channels/<channel_id>/messages`.
90
+
91
+ All outbound Discord sends use `allowed_mentions: { parse: [] }`. Discord interaction tokens and bot tokens must not appear in delivery, queue, buffer, or doctor API responses.
92
+
93
+ Discord audio is not supported in V1; do not configure `audio` on `discordChannel`.
@@ -0,0 +1,56 @@
1
+ # Slack Channel
2
+
3
+ Slack uses Events API webhooks.
4
+
5
+ V1 supports:
6
+
7
+ - `app_mention` in channels.
8
+ - `message.im` direct messages.
9
+ - Outbound replies through `chat.postMessage`.
10
+
11
+ V1 does not support Socket Mode, files, audio transcription, app-management automation, or all-channel message listening.
12
+
13
+ ## Required Secrets
14
+
15
+ ```txt
16
+ SLACK_BOT_TOKEN
17
+ SLACK_SIGNING_SECRET
18
+ ```
19
+
20
+ ## Config
21
+
22
+ ```ts
23
+ slackChannel({
24
+ name: "support-slack",
25
+ })
26
+ ```
27
+
28
+ ## Commands
29
+
30
+ ```sh
31
+ agentkit deploy
32
+ agentkit secret set SLACK_BOT_TOKEN --stdin
33
+ agentkit secret set SLACK_SIGNING_SECRET --stdin
34
+ agentkit channels connect slack support-slack
35
+ agentkit channels test support-slack --message "hello"
36
+ agentkit channels deliveries list support-slack
37
+ ```
38
+
39
+ ## Slack Setup
40
+
41
+ In Slack app configuration:
42
+
43
+ 1. Basic Information: copy Signing Secret into `SLACK_SIGNING_SECRET`.
44
+ 2. OAuth & Permissions: add bot scopes `app_mentions:read`, `im:history`, and `chat:write`.
45
+ 3. Install or reinstall the app to the workspace.
46
+ 4. Copy the Bot User OAuth Token into `SLACK_BOT_TOKEN`.
47
+ 5. Event Subscriptions: enable events and paste the AgentKit webhook URL.
48
+ 6. Subscribe to bot events `app_mention` and `message.im`.
49
+
50
+ ## Runtime Behavior
51
+
52
+ AgentKit verifies `X-Slack-Signature` and `X-Slack-Request-Timestamp` against the raw body before processing events. It rejects stale timestamps, answers `url_verification` with the literal challenge, skips bot/subtype messages, maps channel mentions to Slack threads, maps DMs to the Slack DM channel and user, and replies with `chat.postMessage`.
53
+
54
+ Outbound Slack text escapes Slack control mentions and disables link-name expansion and unfurls.
55
+
56
+ Slack audio is not supported in V1; do not configure `audio` on `slackChannel`.