@copilotkit/runtime 1.70.3 → 1.71.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.
- package/dist/agent/index.cjs +5 -1
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts +1 -1
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +5 -1
- package/dist/agent/index.mjs.map +1 -1
- package/dist/package.cjs +3 -3
- package/dist/package.mjs +3 -3
- package/package.json +5 -6
- package/skills/runtime/SKILL.md +0 -98
- package/skills/runtime/references/agent-runners-custom.md +0 -161
- package/skills/runtime/references/agent-runners-in-memory.md +0 -79
- package/skills/runtime/references/agent-runners-sqlite.md +0 -90
- package/skills/runtime/references/agent-runners.md +0 -336
- package/skills/runtime/references/built-in-agent-factory-modes.md +0 -232
- package/skills/runtime/references/built-in-agent-helper-utilities.md +0 -123
- package/skills/runtime/references/built-in-agent-model-identifiers.md +0 -58
- package/skills/runtime/references/built-in-agent.md +0 -523
- package/skills/runtime/references/intelligence-mode.md +0 -364
- package/skills/runtime/references/middleware.md +0 -376
- package/skills/runtime/references/server-side-tools.md +0 -414
- package/skills/runtime/references/setup-endpoint.md +0 -503
- package/skills/runtime/references/transcription.md +0 -287
- package/skills/runtime/references/wiring-a2a.md +0 -40
- package/skills/runtime/references/wiring-adk.md +0 -45
- package/skills/runtime/references/wiring-ag2.md +0 -41
- package/skills/runtime/references/wiring-agno.md +0 -40
- package/skills/runtime/references/wiring-aws-strands.md +0 -59
- package/skills/runtime/references/wiring-crewai-crews.md +0 -51
- package/skills/runtime/references/wiring-crewai-flows.md +0 -45
- package/skills/runtime/references/wiring-external-agents.md +0 -348
- package/skills/runtime/references/wiring-langgraph.md +0 -49
- package/skills/runtime/references/wiring-llamaindex.md +0 -39
- package/skills/runtime/references/wiring-mastra.md +0 -70
- package/skills/runtime/references/wiring-mcp-apps-middleware.md +0 -73
- package/skills/runtime/references/wiring-ms-agent-framework.md +0 -41
- package/skills/runtime/references/wiring-pydantic-ai.md +0 -45
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
# CopilotKit Intelligence Mode
|
|
2
|
-
|
|
3
|
-
Published version: https://docs.copilotkit.ai/intelligence/connect-your-runtime
|
|
4
|
-
|
|
5
|
-
Intelligence currently ships as a managed cloud service. The only supported `apiUrl` /
|
|
6
|
-
`wsUrl` today is the CopilotKit-managed cloud Intelligence instance — the `ɵ`-prefixed
|
|
7
|
-
runtime internals and REST/WebSocket contract that back Intelligence are still
|
|
8
|
-
stabilizing. `organizationId` is not part of `CopilotKitIntelligenceConfig` today — the key
|
|
9
|
-
alone scopes the project — and is reserved for future self-hosted deployments. If you
|
|
10
|
-
need on-prem durable threads today, use SSE mode with a persistent runner
|
|
11
|
-
(`SqliteAgentRunner` or a custom one) instead.
|
|
12
|
-
|
|
13
|
-
Obtain `apiKey` from the CopilotKit Intelligence dashboard, or let `copilotkit project select`
|
|
14
|
-
provision a project-scoped key into `.env` as `CPK_INTELLIGENCE_API_KEY`.
|
|
15
|
-
|
|
16
|
-
### URL format
|
|
17
|
-
|
|
18
|
-
**Omit `apiUrl` and `wsUrl`.** Both default to the managed platform
|
|
19
|
-
(`https://api.intelligence.copilotkit.ai` and
|
|
20
|
-
`wss://realtime.intelligence.copilotkit.ai`), so `apiKey` is the only URL-related
|
|
21
|
-
config you need. Never invent or guess these values — leaving them unset is always
|
|
22
|
-
correct against the managed service.
|
|
23
|
-
|
|
24
|
-
If you do set them (non-production or a future self-hosted deployment), the client
|
|
25
|
-
prepends `/api/...` and the Intelligence websocket layer derives `/runner` or
|
|
26
|
-
`/client` suffixes internally. Pass the bare base URLs — do NOT append `/api`,
|
|
27
|
-
`/socket`, `/runner`, or `/client` yourself:
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
// Correct — bare base URLs, and note the two planes are DIFFERENT hosts
|
|
31
|
-
apiUrl: "https://api.intelligence.copilotkit.ai",
|
|
32
|
-
wsUrl: "wss://realtime.intelligence.copilotkit.ai",
|
|
33
|
-
|
|
34
|
-
// Wrong — adding /api produces /api/api/... on every REST call; /socket/runner is not a real path
|
|
35
|
-
apiUrl: "https://api.intelligence.copilotkit.ai/api",
|
|
36
|
-
wsUrl: "wss://realtime.intelligence.copilotkit.ai/socket",
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
`apiUrl` and `wsUrl` are **separate hosts** (`api.…` vs `realtime.…`), so you cannot
|
|
40
|
-
produce one from the other by swapping the scheme. Deriving `wsUrl` as
|
|
41
|
-
`apiUrl.replace(/^http/, "ws")` yields `wss://api.intelligence.copilotkit.ai`, which
|
|
42
|
-
serves no socket — and the resulting failure is a silent hang, not an error, because
|
|
43
|
-
the socket layer treats an unreachable host as a retryable reconnect. For the same
|
|
44
|
-
reason, override the two together or not at all: setting one alone leaves the other
|
|
45
|
-
plane on the managed host, which the client warns about at construction.
|
|
46
|
-
|
|
47
|
-
Source: `packages/runtime/src/v2/runtime/intelligence-platform/client.ts:41-46, 259,
|
|
48
|
-
356-357, 437, 468, 682-708`.
|
|
49
|
-
|
|
50
|
-
## Setup
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import {
|
|
54
|
-
CopilotRuntime,
|
|
55
|
-
CopilotKitIntelligence,
|
|
56
|
-
createCopilotRuntimeHandler,
|
|
57
|
-
} from "@copilotkit/runtime/v2";
|
|
58
|
-
|
|
59
|
-
const intelligence = new CopilotKitIntelligence({
|
|
60
|
-
// apiUrl / wsUrl default to cloud-hosted CopilotKit Intelligence — leave them unset.
|
|
61
|
-
apiKey: process.env.CPK_INTELLIGENCE_API_KEY!,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const runtime = new CopilotRuntime({
|
|
65
|
-
agents: {
|
|
66
|
-
/* ... */
|
|
67
|
-
} as any,
|
|
68
|
-
intelligence,
|
|
69
|
-
identifyUser: (request) => ({
|
|
70
|
-
id: request.headers.get("x-user-id") ?? "anonymous",
|
|
71
|
-
}),
|
|
72
|
-
// Optional tuning:
|
|
73
|
-
generateThreadNames: true, // default true — 1 LLM call per new thread
|
|
74
|
-
lockTtlSeconds: 20, // clamped to ≤ 3600
|
|
75
|
-
lockHeartbeatIntervalSeconds: 15, // clamped to ≤ 3000
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const handler = createCopilotRuntimeHandler({
|
|
79
|
-
runtime,
|
|
80
|
-
basePath: "/api/copilotkit",
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
export default { fetch: handler };
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
When `intelligence` is set, the runtime auto-wires `IntelligenceAgentRunner` internally.
|
|
87
|
-
Do NOT pass `runner` — see the failure-modes section.
|
|
88
|
-
|
|
89
|
-
## Core Patterns
|
|
90
|
-
|
|
91
|
-
### Identify the user from an auth cookie
|
|
92
|
-
|
|
93
|
-
`identifyUser` is for user identification only — it does NOT forward thrown `Response`s.
|
|
94
|
-
`resolveIntelligenceUser` (`handlers/shared/resolve-intelligence-user.ts:14-24`) wraps the
|
|
95
|
-
call in try/catch and converts any thrown value (including `Response`) into a generic
|
|
96
|
-
`errorResponse("Failed to identify user", 500)`. Gate auth in `hooks.onRequest`
|
|
97
|
-
(see the `middleware` skill) and keep `identifyUser` focused on returning an id:
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import {
|
|
101
|
-
CopilotRuntime,
|
|
102
|
-
createCopilotRuntimeHandler,
|
|
103
|
-
} from "@copilotkit/runtime/v2";
|
|
104
|
-
import { parse } from "cookie";
|
|
105
|
-
|
|
106
|
-
const runtime = new CopilotRuntime({
|
|
107
|
-
agents,
|
|
108
|
-
intelligence,
|
|
109
|
-
// identifyUser returns the id; auth rejection is hooked elsewhere.
|
|
110
|
-
identifyUser: async (request) => {
|
|
111
|
-
const cookies = parse(request.headers.get("cookie") ?? "");
|
|
112
|
-
const user = await resolveSession(cookies["session"]); // your auth lib
|
|
113
|
-
return { id: user?.id ?? "anonymous" };
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const handler = createCopilotRuntimeHandler({
|
|
118
|
-
runtime,
|
|
119
|
-
basePath: "/api/copilotkit",
|
|
120
|
-
hooks: {
|
|
121
|
-
onRequest: async ({ request }) => {
|
|
122
|
-
const cookies = parse(request.headers.get("cookie") ?? "");
|
|
123
|
-
const user = await resolveSession(cookies["session"]);
|
|
124
|
-
// onRequest DOES forward thrown Responses — use it for auth rejection.
|
|
125
|
-
if (!user) throw new Response("Unauthorized", { status: 401 });
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
async function resolveSession(token: string | undefined) {
|
|
131
|
-
if (!token) return null;
|
|
132
|
-
return { id: "user-123" };
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Disable thread-name generation to avoid a per-thread LLM call
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
new CopilotRuntime({
|
|
140
|
-
agents,
|
|
141
|
-
intelligence,
|
|
142
|
-
identifyUser: (req) => ({ id: req.headers.get("x-user-id")! }),
|
|
143
|
-
generateThreadNames: false,
|
|
144
|
-
});
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Frontend — no config change
|
|
148
|
-
|
|
149
|
-
The frontend reads `GET /info` on mount. When the runtime reports `mode: "intelligence"`
|
|
150
|
-
and an `intelligence.wsUrl`, `CopilotKitCore` auto-switches from SSE to the websocket
|
|
151
|
-
transport. The React integration just points at the runtime URL:
|
|
152
|
-
|
|
153
|
-
```tsx
|
|
154
|
-
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
155
|
-
|
|
156
|
-
export function App({ children }: { children: React.ReactNode }) {
|
|
157
|
-
return <CopilotKit runtimeUrl="/api/copilotkit">{children}</CopilotKit>;
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## Common Mistakes
|
|
162
|
-
|
|
163
|
-
### CRITICAL Missing identifyUser
|
|
164
|
-
|
|
165
|
-
Wrong:
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
new CopilotRuntime({ agents, intelligence });
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Correct:
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
new CopilotRuntime({
|
|
175
|
-
agents,
|
|
176
|
-
intelligence,
|
|
177
|
-
identifyUser: (req) => ({ id: req.headers.get("x-user-id")! }),
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
`identifyUser` is required on `CopilotIntelligenceRuntimeOptions` — omitting it is a
|
|
182
|
-
TypeScript error and (if suppressed) crashes handlers at request time. Every thread is
|
|
183
|
-
scoped to a user ID.
|
|
184
|
-
|
|
185
|
-
Source: `packages/runtime/src/v2/runtime/core/runtime.ts:156-160`.
|
|
186
|
-
|
|
187
|
-
### CRITICAL Deriving wsUrl from apiUrl, adding /api or /socket suffixes, or pointing at an unsupported self-hosted server
|
|
188
|
-
|
|
189
|
-
Wrong:
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
new CopilotKitIntelligence({
|
|
193
|
-
apiUrl: "https://api.intelligence.copilotkit.ai",
|
|
194
|
-
// Scheme-swapped from apiUrl — WRONG HOST. Serves no socket; hangs instead of erroring.
|
|
195
|
-
wsUrl: apiUrl.replace(/^http/, "ws"),
|
|
196
|
-
apiKey,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
new CopilotKitIntelligence({
|
|
200
|
-
apiUrl: "https://api.intelligence.copilotkit.ai/api", // double /api prefix
|
|
201
|
-
wsUrl: "wss://realtime.intelligence.copilotkit.ai/socket", // /socket is not a real path
|
|
202
|
-
apiKey,
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
new CopilotKitIntelligence({
|
|
206
|
-
apiUrl: "https://internal.myco.com/intelligence", // self-hosting is not yet supported
|
|
207
|
-
wsUrl: "wss://internal.myco.com/intelligence",
|
|
208
|
-
apiKey,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
new CopilotKitIntelligence({
|
|
212
|
-
// Only one plane overridden — wsUrl silently stays on the managed host. Warns, then hangs.
|
|
213
|
-
apiUrl: "https://api.intelligence.copilotkit.ai",
|
|
214
|
-
apiKey,
|
|
215
|
-
});
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
Correct:
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
new CopilotKitIntelligence({
|
|
222
|
-
// No apiUrl / wsUrl — they default to the managed platform.
|
|
223
|
-
apiKey: process.env.CPK_INTELLIGENCE_API_KEY!,
|
|
224
|
-
});
|
|
225
|
-
// For on-prem durability without Intelligence: SSE mode + SqliteAgentRunner.
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
Three failure modes to avoid:
|
|
229
|
-
|
|
230
|
-
1. The API and realtime planes are **different hosts**, so `wsUrl` cannot be derived
|
|
231
|
-
from `apiUrl`. A scheme-only swap keeps the API host (and port) and produces a URL
|
|
232
|
-
that serves no socket. This one is expensive to debug: a wrong `apiUrl` fails fast
|
|
233
|
-
with an HTTP error, while a wrong `wsUrl` sits in `connecting` until the settle
|
|
234
|
-
timeout and reports only "did not settle in time".
|
|
235
|
-
2. The client prepends `/api/...` to every REST call (`#request` at line 356-357) and
|
|
236
|
-
the websocket layer derives `/runner` / `/client` suffixes from `wsUrl` internally.
|
|
237
|
-
Passing `apiUrl: ".../api"` produces double-prefixed `/api/api/threads`; passing
|
|
238
|
-
`wsUrl: ".../socket"` produces a broken `.../socket/runner` upgrade path.
|
|
239
|
-
3. Self-hosting Intelligence is not yet supported. The `ɵ`-prefixed runtime internals
|
|
240
|
-
and REST/WebSocket contract are still stabilizing. `organizationId` is not a constructor
|
|
241
|
-
option today; it is reserved for future self-hosted instances. For on-prem durable
|
|
242
|
-
threads today, use SSE mode +
|
|
243
|
-
`SqliteAgentRunner` (see `copilotkit/agent-runners`).
|
|
244
|
-
|
|
245
|
-
Source: `packages/runtime/src/v2/runtime/intelligence-platform/client.ts:41-46, 68-69,
|
|
246
|
-
259, 356-357, 437, 682-708`.
|
|
247
|
-
|
|
248
|
-
### HIGH Setting runner alongside intelligence
|
|
249
|
-
|
|
250
|
-
Wrong:
|
|
251
|
-
|
|
252
|
-
```typescript
|
|
253
|
-
import { SqliteAgentRunner } from "@copilotkit/sqlite-runner";
|
|
254
|
-
|
|
255
|
-
new CopilotRuntime({
|
|
256
|
-
agents,
|
|
257
|
-
intelligence,
|
|
258
|
-
runner: new SqliteAgentRunner({ dbPath: "./threads.db" }),
|
|
259
|
-
});
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
Correct:
|
|
263
|
-
|
|
264
|
-
```typescript
|
|
265
|
-
new CopilotRuntime({
|
|
266
|
-
agents,
|
|
267
|
-
intelligence,
|
|
268
|
-
identifyUser,
|
|
269
|
-
});
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
`CopilotIntelligenceRuntimeOptions` excludes `runner` at the type level. Intelligence
|
|
273
|
-
forces its own `IntelligenceAgentRunner` tied to the Intelligence service WebSocket; a user-supplied
|
|
274
|
-
runner is rejected.
|
|
275
|
-
|
|
276
|
-
Source: `packages/runtime/src/v2/runtime/core/runtime.ts:149-173,285-294`.
|
|
277
|
-
|
|
278
|
-
### HIGH Calling /threads against an SSE-mode runtime
|
|
279
|
-
|
|
280
|
-
Wrong:
|
|
281
|
-
|
|
282
|
-
```typescript
|
|
283
|
-
// SSE-only runtime (no `intelligence` configured)
|
|
284
|
-
await fetch("/api/copilotkit/threads");
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
Correct:
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
// Enable Intelligence mode first, OR don't call thread routes.
|
|
291
|
-
// Client-side, the useThreads hook errors with "Runtime URL is not configured" when
|
|
292
|
-
// the runtime isn't in Intelligence mode.
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
The `/threads`, `/threads/subscribe`, `PATCH /threads/:id`, `POST /threads/:id/archive`,
|
|
296
|
-
`DELETE /threads/:id`, and `/threads/:id/messages` routes always resolve in the router,
|
|
297
|
-
but the handlers call `requireIntelligenceRuntime(runtime)` first and return HTTP 422
|
|
298
|
-
("Missing CopilotKitIntelligence configuration. Thread operations require a
|
|
299
|
-
CopilotKitIntelligence instance to be provided in CopilotRuntime options.") when the
|
|
300
|
-
runtime isn't an `IntelligenceRuntime`.
|
|
301
|
-
|
|
302
|
-
Source: `packages/runtime/src/v2/runtime/handlers/intelligence/threads.ts:37-48`;
|
|
303
|
-
route table in `dev-docs/architecture/setup-intelligence.md:179-183`.
|
|
304
|
-
|
|
305
|
-
### LOW Over-clamping lockTtlSeconds
|
|
306
|
-
|
|
307
|
-
Wrong:
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
new CopilotRuntime({
|
|
311
|
-
agents,
|
|
312
|
-
intelligence,
|
|
313
|
-
identifyUser,
|
|
314
|
-
lockTtlSeconds: 86400, // "I want 1-day lock"
|
|
315
|
-
});
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
Correct:
|
|
319
|
-
|
|
320
|
-
```typescript
|
|
321
|
-
new CopilotRuntime({
|
|
322
|
-
agents,
|
|
323
|
-
intelligence,
|
|
324
|
-
identifyUser,
|
|
325
|
-
lockTtlSeconds: 3600, // max is 1 hour
|
|
326
|
-
});
|
|
327
|
-
// Rethink long-running workflows if 1 hour is insufficient.
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
`lockTtlSeconds` is silently `Math.min(value, 3600)`; `lockHeartbeatIntervalSeconds` is
|
|
331
|
-
`Math.min(value, 3000)`. Requests over the cap are clamped without warning.
|
|
332
|
-
|
|
333
|
-
Source: `packages/runtime/src/v2/runtime/core/runtime.ts:281-307`.
|
|
334
|
-
|
|
335
|
-
### MEDIUM generateThreadNames unset expecting no LLM cost
|
|
336
|
-
|
|
337
|
-
Wrong:
|
|
338
|
-
|
|
339
|
-
```typescript
|
|
340
|
-
new CopilotRuntime({ agents, intelligence, identifyUser });
|
|
341
|
-
// assumes no extra LLM spend
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
Correct:
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
new CopilotRuntime({
|
|
348
|
-
agents,
|
|
349
|
-
intelligence,
|
|
350
|
-
identifyUser,
|
|
351
|
-
generateThreadNames: false,
|
|
352
|
-
});
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
`generateThreadNames` defaults to `true`. Every newly created thread triggers an extra
|
|
356
|
-
LLM call on the Intelligence service side to generate a short name, billed against your Intelligence quota.
|
|
357
|
-
|
|
358
|
-
Source: `packages/runtime/src/v2/runtime/core/runtime.ts` (generateThreadNames default).
|
|
359
|
-
|
|
360
|
-
## See also
|
|
361
|
-
|
|
362
|
-
- `copilotkit/agent-runners` — Intelligence forces `IntelligenceAgentRunner`
|
|
363
|
-
- `copilotkit/setup-endpoint` — `/threads/*` routes flip on with Intelligence
|
|
364
|
-
- `copilotkit/threads` (react-core) — `useThreads` depends on Intelligence routes
|