@andreprado/agentkit 0.1.0-alpha.8 → 0.1.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 (117) 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 +1185 -50
  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 +68 -8
  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 +896 -0
  47. package/src/runtime/channels/generic-webhook.ts +974 -0
  48. package/src/runtime/channels/slack.ts +646 -0
  49. package/src/runtime/channels/telegram.ts +466 -23
  50. package/src/runtime/channels/whatsapp-evolution.ts +1357 -0
  51. package/src/runtime/channels/whatsapp-meta.ts +9 -0
  52. package/src/runtime/channels/whatsapp-uazapi.ts +1323 -0
  53. package/src/runtime/channels/whatsapp-zapster.ts +674 -40
  54. package/src/runtime/channels.ts +89 -4
  55. package/src/runtime/chat.ts +70 -44
  56. package/src/runtime/config.ts +489 -20
  57. package/src/runtime/core/manifest.ts +75 -5
  58. package/src/runtime/core/targets.ts +5 -5
  59. package/src/runtime/deploy-readiness.ts +34 -4
  60. package/src/runtime/dev-server.ts +639 -39
  61. package/src/runtime/env.ts +8 -3
  62. package/src/runtime/evals.ts +445 -74
  63. package/src/runtime/improve.ts +868 -0
  64. package/src/runtime/inspect.ts +173 -4
  65. package/src/runtime/integrations/composio.ts +425 -0
  66. package/src/runtime/knowledge/retrieve.ts +25 -5
  67. package/src/runtime/knowledge/schema.ts +45 -1
  68. package/src/runtime/prompt-context.ts +141 -0
  69. package/src/runtime/runtime-contract.ts +71 -7
  70. package/src/runtime/skills.ts +95 -0
  71. package/src/runtime/targets/cloudflare/build.ts +1010 -208
  72. package/src/runtime/targets/container/server.ts +1 -1
  73. package/src/runtime/targets/vps/deploy.ts +26 -9
  74. package/src/runtime/tool-runner.ts +9 -1
  75. package/src/runtime/tools.ts +26 -2
  76. package/src/runtime/transcription.ts +483 -0
  77. package/src/storage/sqlite.ts +7 -2
  78. package/src/templates/blank.ts +37 -9
  79. package/src/templates/dentista.ts +40 -14
  80. package/src/templates/skills/agentkit-build-agent/SKILL.md +34 -5
  81. package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +2 -1
  82. package/src/templates/skills/agentkit-capsule/SKILL.md +32 -3
  83. package/src/templates/skills/agentkit-capsule/references/docs-router.md +2 -2
  84. package/src/templates/skills/agentkit-channels/SKILL.md +71 -6
  85. package/src/templates/skills/agentkit-channels/references/channel-buffering.md +9 -2
  86. package/src/templates/skills/agentkit-channels/references/channel-debugging.md +34 -5
  87. package/src/templates/skills/agentkit-channels/references/discord.md +93 -0
  88. package/src/templates/skills/agentkit-channels/references/slack.md +56 -0
  89. package/src/templates/skills/agentkit-channels/references/telegram.md +39 -4
  90. package/src/templates/skills/agentkit-channels/references/whatsapp-evolution.md +57 -0
  91. package/src/templates/skills/agentkit-channels/references/whatsapp-uazapi.md +54 -0
  92. package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +42 -8
  93. package/src/templates/skills/agentkit-database/SKILL.md +11 -0
  94. package/src/templates/skills/agentkit-deploy/SKILL.md +9 -1
  95. package/src/templates/skills/agentkit-evals/SKILL.md +77 -13
  96. package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +13 -6
  97. package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +8 -4
  98. package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +8 -4
  99. package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +16 -7
  100. package/src/templates/skills/agentkit-improve/SKILL.md +96 -0
  101. package/src/templates/skills/agentkit-improve/references/replay-side-effects.md +18 -0
  102. package/src/templates/skills/agentkit-improve/references/trace-packets.md +22 -0
  103. package/src/templates/skills/agentkit-improve/templates/regression.eval.md +18 -0
  104. package/src/templates/skills/agentkit-integrations/SKILL.md +98 -0
  105. package/src/templates/skills/agentkit-knowledge/SKILL.md +4 -1
  106. package/src/templates/skills/agentkit-prompts/SKILL.md +3 -1
  107. package/src/templates/skills/agentkit-provider/SKILL.md +29 -4
  108. package/src/templates/skills/agentkit-security/SKILL.md +5 -2
  109. package/src/templates/skills/agentkit-tools/SKILL.md +8 -1
  110. package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +8 -8
  111. package/src/templates/skills/agentkit-tools/examples/jev-service-fit.tool.md +110 -0
  112. package/src/templates/skills/agentkit-troubleshooting/SKILL.md +25 -1
  113. package/src/templates/support.ts +42 -12
  114. package/docs/guides/agentkit-skills-architecture.md +0 -471
  115. package/docs/guides/channels-implementation-map.md +0 -243
  116. package/docs/guides/channels-production-handoff.md +0 -101
  117. package/docs/portable-deploy-release-checklist.md +0 -41
@@ -1,16 +1,28 @@
1
1
  import type { AgentChannel, ChannelProvider, ChannelType } from "../index";
2
2
 
3
3
  export type ChannelMessageRole = "user" | "assistant";
4
- export type ChannelMessageContentType = "text";
4
+ export type ChannelMessageContentType = "text" | "audio";
5
5
  export type ChannelEventKind = "message" | "delivery_status" | "unsupported";
6
6
  export type ChannelDeliveryDirection = "inbound" | "outbound";
7
7
  export type ChannelDeliveryState =
8
+ | "webhook_received"
8
9
  | "received"
9
10
  | "validated"
11
+ | "audio_received"
12
+ | "audio_downloaded"
13
+ | "transcribing"
14
+ | "transcribed"
10
15
  | "duplicate"
11
16
  | "buffered"
12
17
  | "queued"
13
18
  | "running"
19
+ | "agent_completed"
20
+ | "adapter_stubbed"
21
+ | "provider_request_built"
22
+ | "provider_sent"
23
+ | "outbound_sent"
24
+ | "provider_failed"
25
+ | "synthetic_expected_failure"
14
26
  | "sent"
15
27
  | "delivered"
16
28
  | "failed"
@@ -37,11 +49,41 @@ export type ChannelExternalIdentity = {
37
49
  redactedDisplay?: string;
38
50
  };
39
51
 
52
+ export type ChannelReplyTarget =
53
+ | {
54
+ type: "discord_interaction";
55
+ applicationId: string;
56
+ interactionId: string;
57
+ interactionToken: string;
58
+ }
59
+ | {
60
+ type: "discord_message";
61
+ channelId: string;
62
+ messageId: string;
63
+ }
64
+ | {
65
+ type: "slack_message";
66
+ channelId: string;
67
+ messageTs: string;
68
+ threadTs?: string;
69
+ };
70
+
71
+ export type ChannelAudioAttachment = {
72
+ providerMediaId: string;
73
+ kind: "voice" | "audio";
74
+ mimeType?: string;
75
+ filename?: string;
76
+ durationSeconds?: number;
77
+ sizeBytes?: number;
78
+ downloadUrl?: string;
79
+ };
80
+
40
81
  export type NormalizedChannelMessage = {
41
82
  role: ChannelMessageRole;
42
83
  contentType: ChannelMessageContentType;
43
84
  content: string;
44
85
  providerMessageId?: string;
86
+ audio?: ChannelAudioAttachment;
45
87
  };
46
88
 
47
89
  export type NormalizedChannelEvent = ChannelAdapterId & {
@@ -54,6 +96,7 @@ export type NormalizedChannelEvent = ChannelAdapterId & {
54
96
  receivedAt: string;
55
97
  unsupportedReason?: string;
56
98
  providerMetadata?: Record<string, unknown>;
99
+ replyTarget?: ChannelReplyTarget;
57
100
  };
58
101
 
59
102
  export type WebhookVerificationInput = RawWebhookEvent & {
@@ -71,26 +114,66 @@ export type WebhookVerificationResult =
71
114
  message: string;
72
115
  };
73
116
 
117
+ export type ChannelWebhookResponse = {
118
+ status?: number;
119
+ headers?: Record<string, string>;
120
+ body: string | Record<string, unknown>;
121
+ };
122
+
74
123
  export type ChannelSendInput = ChannelAdapterId & {
75
124
  channelId: string;
125
+ channel?: AgentChannel;
126
+ jobId?: string;
127
+ deliveryId?: string;
76
128
  conversationId: string;
77
129
  externalIdentity: ChannelExternalIdentity;
130
+ replyTarget?: ChannelReplyTarget;
78
131
  message: NormalizedChannelMessage;
79
132
  secrets: Record<string, string>;
80
133
  };
81
134
 
135
+ export type ChannelMediaDownloadInput = ChannelAdapterId & {
136
+ channelId: string;
137
+ message: NormalizedChannelMessage;
138
+ secrets: Record<string, string>;
139
+ maxBytes?: number;
140
+ };
141
+
142
+ export type ChannelMediaDownloadResult =
143
+ | {
144
+ ok: true;
145
+ audio: Uint8Array;
146
+ filename: string;
147
+ mimeType?: string;
148
+ durationSeconds?: number;
149
+ sizeBytes?: number;
150
+ providerMetadata?: Record<string, unknown>;
151
+ }
152
+ | {
153
+ ok: false;
154
+ retryable: boolean;
155
+ code:
156
+ | "channel_secret_missing"
157
+ | "channel_audio_download_unavailable"
158
+ | "channel_audio_too_large"
159
+ | "channel_provider_unavailable"
160
+ | "channel_media_download_failed";
161
+ message: string;
162
+ providerMetadata?: Record<string, unknown>;
163
+ };
164
+
82
165
  export type ChannelSendResult =
83
166
  | {
84
167
  ok: true;
85
168
  providerRequestId?: string;
86
169
  providerMessageId?: string;
87
- status: "sent" | "delivered";
170
+ status: "stubbed" | "sent" | "delivered";
88
171
  providerMetadata?: Record<string, unknown>;
89
172
  }
90
173
  | {
91
174
  ok: false;
92
175
  retryable: boolean;
93
- code: "channel_secret_missing" | "channel_provider_unavailable" | "channel_send_failed";
176
+ code: "channel_secret_missing" | "channel_provider_unavailable" | "channel_send_failed" | "synthetic_expected_failure";
94
177
  message: string;
95
178
  providerRequestId?: string;
96
179
  providerMetadata?: Record<string, unknown>;
@@ -112,13 +195,15 @@ export type ChannelStatusResult = {
112
195
  export type ChannelAdapter = ChannelAdapterId & {
113
196
  requiredSecrets: string[];
114
197
  normalizeInbound(input: RawWebhookEvent): Promise<NormalizedChannelEvent[]> | NormalizedChannelEvent[];
198
+ downloadMedia?(input: ChannelMediaDownloadInput): Promise<ChannelMediaDownloadResult>;
115
199
  sendMessage(input: ChannelSendInput): Promise<ChannelSendResult>;
116
200
  verifyWebhook?(input: WebhookVerificationInput): Promise<WebhookVerificationResult> | WebhookVerificationResult;
201
+ getWebhookResponse?(input: WebhookVerificationInput): Promise<ChannelWebhookResponse | null> | ChannelWebhookResponse | null;
117
202
  getStatus?(input: ChannelStatusInput): Promise<ChannelStatusResult> | ChannelStatusResult;
118
203
  };
119
204
 
120
205
  export type PortableChannelRouteContract = {
121
- route: "/channels/:name/:type/:provider/webhook";
206
+ route: "/channels/:name/:type/:provider/webhook" | "/channels/:name/webhook";
122
207
  verification: WebhookVerificationResult;
123
208
  dedupe: {
124
209
  key: string;
@@ -1,3 +1,4 @@
1
+ import { getCodexApiKey } from "../providers/codex-auth";
1
2
  import { getProviderAdapter } from "../providers";
2
3
  import type { AgentMessage, ProviderRunResult } from "../providers";
3
4
  import type { ToolRuntimeContext } from "../index";
@@ -7,9 +8,11 @@ import { loadAgentCapsule } from "./config";
7
8
  import { openPreparedCapsuleStore } from "./database";
8
9
  import { loadCapsuleEnv } from "./env";
9
10
  import { AgentKitError, isAgentKitError } from "./errors";
11
+ import { createManagedComposioTools } from "./integrations/composio";
10
12
  import { syncConfiguredKnowledgeSources } from "./knowledge/ingest";
11
13
  import { appendKnowledgePromptPolicy } from "./knowledge/prompt-policy";
12
14
  import { createKnowledgeSearchTool } from "./knowledge/tool";
15
+ import { appendRuntimePromptContext, buildRuntimeClockContext } from "./prompt-context";
13
16
  import { createToolRuntime } from "./tools";
14
17
 
15
18
  export type RunAgentMessageOptions = {
@@ -17,6 +20,8 @@ export type RunAgentMessageOptions = {
17
20
  conversationId?: string;
18
21
  signal?: AbortSignal;
19
22
  runtime?: Partial<ToolRuntimeContext>;
23
+ now?: Date;
24
+ localStoragePath?: string;
20
25
  };
21
26
 
22
27
  export type AgentRunResult = ProviderRunResult & PersistedChatRun;
@@ -25,7 +30,8 @@ export async function runAgentMessageFromCwd(
25
30
  cwd: string,
26
31
  options: RunAgentMessageOptions,
27
32
  ): Promise<AgentRunResult> {
28
- return runAgentMessage(await loadAgentCapsule(cwd), options);
33
+ const capsule = await loadAgentCapsule(cwd);
34
+ return runAgentMessage(withLocalStoragePath(capsule, options.localStoragePath), options);
29
35
  }
30
36
 
31
37
  export async function runAgentMessage(
@@ -41,56 +47,70 @@ export async function runAgentMessage(
41
47
  const adapter = getProviderAdapter(capsule.config.provider);
42
48
  const env = await loadCapsuleEnv(capsule.root);
43
49
  await syncConfiguredKnowledgeSources(capsule);
44
- const { store } = await openPreparedCapsuleStore(capsule);
45
50
  const conversationId = normalizeConversationId(options.conversationId);
46
- const { conversation, previousMessages } = resolveConversation(store, {
47
- agentName: capsule.config.name,
48
- conversationId,
49
- firstMessage: content,
50
- });
51
- const messages: AgentMessage[] = [...previousMessages, { role: "user", content }];
52
- const userMessage = store.appendMessage({
53
- conversationId: conversation.id,
54
- role: "user",
55
- content,
56
- });
57
- const run = store.createRun({
58
- conversationId: conversation.id,
59
- provider: capsule.config.provider.name,
60
- model: capsule.config.provider.model,
61
- });
62
- const runtimeTools = withKnowledgeTools(capsule);
63
- const toolRuntime = createToolRuntime({
64
- tools: runtimeTools,
65
- store,
66
- runId: run.id,
67
- conversationId: conversation.id,
68
- env,
69
- signal: options.signal,
70
- runtime: {
71
- environment: "local",
72
- invocation: "chat",
73
- target: "bun",
74
- database: "sqlite",
75
- ...options.runtime,
76
- },
77
- });
51
+ const { store } = await openPreparedCapsuleStore(capsule);
52
+ let runId: string | null = null;
78
53
 
79
54
  try {
55
+ const { conversation, previousMessages } = resolveConversation(store, {
56
+ agentName: capsule.config.name,
57
+ conversationId,
58
+ firstMessage: content,
59
+ });
60
+ const messages: AgentMessage[] = [...previousMessages, { role: "user", content }];
61
+ const userMessage = store.appendMessage({
62
+ conversationId: conversation.id,
63
+ role: "user",
64
+ content,
65
+ });
66
+ const run = store.createRun({
67
+ conversationId: conversation.id,
68
+ provider: capsule.config.provider.name,
69
+ model: capsule.config.provider.model,
70
+ });
71
+ runId = run.id;
72
+ const runtimeTools = withKnowledgeTools(capsule);
73
+ const clock = buildRuntimeClockContext({
74
+ timeZone: capsule.config.timeZone,
75
+ env,
76
+ now: options.now,
77
+ });
78
+ const toolRuntime = createToolRuntime({
79
+ tools: runtimeTools,
80
+ store,
81
+ runId: run.id,
82
+ conversationId: conversation.id,
83
+ env,
84
+ signal: options.signal,
85
+ clock,
86
+ runtime: {
87
+ environment: "local",
88
+ invocation: "chat",
89
+ target: "bun",
90
+ database: "sqlite",
91
+ ...options.runtime,
92
+ },
93
+ });
80
94
  const result = await adapter.run({
81
95
  agent: {
82
96
  name: capsule.config.name,
83
97
  runtime: capsule.config.runtime,
84
98
  provider: capsule.config.provider,
85
99
  },
86
- instructions: withToolVisibilityInstructions(
87
- appendKnowledgePromptPolicy(capsule.instructions, capsule.config),
88
- runtimeTools,
100
+ instructions: appendRuntimePromptContext(
101
+ withToolVisibilityInstructions(
102
+ appendKnowledgePromptPolicy(capsule.instructions, capsule.config),
103
+ runtimeTools,
104
+ ),
105
+ {
106
+ clock,
107
+ },
89
108
  ),
90
109
  messages,
91
110
  tools: toolRuntime.definitions,
92
111
  toolRuntime,
93
112
  env,
113
+ apiKey: capsule.config.provider.name === "openai-codex" ? await getCodexApiKey() : undefined,
94
114
  signal: options.signal,
95
115
  });
96
116
 
@@ -114,12 +134,14 @@ export async function runAgentMessage(
114
134
  assistantMessageId: assistantMessage.id,
115
135
  };
116
136
  } catch (error) {
117
- store.completeRun({
118
- runId: run.id,
119
- status: "failed",
120
- errorCode: isAgentKitError(error) ? error.code : "runtime_error",
121
- errorMessage: error instanceof Error ? error.message : String(error),
122
- });
137
+ if (runId) {
138
+ store.completeRun({
139
+ runId,
140
+ status: "failed",
141
+ errorCode: isAgentKitError(error) ? error.code : "runtime_error",
142
+ errorMessage: error instanceof Error ? error.message : String(error),
143
+ });
144
+ }
123
145
 
124
146
  throw error;
125
147
  } finally {
@@ -128,7 +150,7 @@ export async function runAgentMessage(
128
150
  }
129
151
 
130
152
  function withKnowledgeTools(capsule: LoadedAgentCapsule): NonNullable<LoadedAgentCapsule["config"]["tools"]> {
131
- const tools = [...(capsule.config.tools ?? [])];
153
+ const tools = [...createManagedComposioTools(capsule.config), ...(capsule.config.tools ?? [])];
132
154
  const knowledgeTool = createKnowledgeSearchTool(capsule);
133
155
 
134
156
  if (knowledgeTool) {
@@ -190,6 +212,10 @@ function normalizeConversationId(value: string | undefined): string | undefined
190
212
  return conversationId;
191
213
  }
192
214
 
215
+ function withLocalStoragePath(capsule: LoadedAgentCapsule, storagePath?: string): LoadedAgentCapsule {
216
+ return storagePath ? { ...capsule, storagePath } : capsule;
217
+ }
218
+
193
219
  function withToolVisibilityInstructions(instructions: string, tools: LoadedAgentCapsule["config"]["tools"] = []): string {
194
220
  const internalTools = tools.filter((tool) => tool.visibility === "internal").map((tool) => tool.name).sort();
195
221