Skip to content

Commit ef3bafe

Browse files
chore: docs sync from main — needs review (2026-04-30)
1 parent e723ef9 commit ef3bafe

44 files changed

Lines changed: 5343 additions & 103 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: AG-UI Middleware
3+
icon: lucide/Layers
4+
description: Configure AG-UI middleware for your CopilotKit application.
5+
hideTOC: true
6+
---
7+
AG-UI agents expose a middleware layer via `agent.use(middleware)`, a powerful hook for logging, guardrails, request transformation, and event rewriting. Because CopilotKit runs the middleware server-side inside the [Copilot Runtime](/backend/copilot-runtime), it executes in a trusted environment where the client cannot tamper with it.
8+
9+
## Defining a Middleware
10+
11+
A middleware extends the `Middleware` base class from `@ag-ui/client` and implements `run(input, next)`. It receives the incoming `RunAgentInput` and returns an `Observable<BaseEvent>`, typically by subscribing to `runNextWithState(input, next)` and transforming the stream:
12+
13+
```ts title="my-middleware.ts"
14+
import {
15+
Middleware,
16+
RunAgentInput,
17+
AbstractAgent,
18+
BaseEvent,
19+
} from "@ag-ui/client";
20+
import { Observable } from "rxjs";
21+
22+
export class LoggingMiddleware extends Middleware {
23+
run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {
24+
return new Observable<BaseEvent>((subscriber) => {
25+
const sub = this.runNextWithState(input, next).subscribe({
26+
next: ({ event }) => {
27+
console.log("[agent event]", event.type);
28+
subscriber.next(event);
29+
},
30+
error: (err) => subscriber.error(err),
31+
complete: () => subscriber.complete(),
32+
});
33+
return () => sub.unsubscribe();
34+
});
35+
}
36+
}
37+
```
38+
39+
## Attaching Middleware to an Agent
40+
41+
Call `.use(...)` on the agent before registering it with the runtime:
42+
43+
```ts title="app/api/copilotkit/route.ts"
44+
import { CopilotRuntime } from "@copilotkit/runtime";
45+
import { LangGraphAgent } from "@copilotkit/runtime/langgraph";
46+
import { LoggingMiddleware } from "./my-middleware";
47+
48+
const agent = new LangGraphAgent({
49+
deploymentUrl: process.env.LANGGRAPH_DEPLOYMENT_URL!,
50+
graphId: "sample_agent",
51+
});
52+
agent.use(new LoggingMiddleware());
53+
54+
const runtime = new CopilotRuntime({
55+
agents: { default: agent },
56+
});
57+
```
58+
59+
## Built-in Middleware
60+
61+
The runtime ships first-class middleware options you can enable directly on `CopilotRuntime` without calling `.use()` on each agent:
62+
63+
- **`a2ui`** — apply `A2UIMiddleware` to all (or a subset of) registered agents. See [Copilot Runtime → A2UI](/backend/copilot-runtime#a2ui).
64+
- **`mcpApps`** — configure MCP servers for all agents from a single place. See [Copilot Runtime → mcpApps](/backend/copilot-runtime#mcpapps).
65+
66+
## Related
67+
68+
- [Copilot Runtime](/backend/copilot-runtime) — the server-side layer that executes middleware.
69+
- [AG-UI Protocol](/backend/ag-ui) — the event stream the middleware operates on.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: AWS AgentCore
3+
icon: "lucide/Cloud"
4+
description: Add a production-ready frontend to your AWS AgentCore agents with CopilotKit.
5+
hideHeader: true
6+
---
7+
<Content />
Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,11 @@
11
---
22
title: Inspector
33
icon: "lucide/SearchCheck"
4-
description: Overlay for debugging AG-UI events, agent state, frontend tools, context, and more — live, on top of your app.
4+
description: Inspector for debugging actions, readables, agent status, messages, and context.
55
---
6-
7-
<video
8-
src="https://cdn.copilotkit.ai/docs/copilotkit/videos/inspector.mp4"
9-
style={{ width: "100%", borderRadius: "0.5rem", marginBottom: "1rem" }}
10-
loop
11-
playsInline
12-
controls
13-
autoPlay
14-
muted
15-
/>
16-
17-
## What it shows
18-
19-
The **CopilotKit Inspector** is a built-in debugging overlay that sits on top of your app. It gives you live visibility into everything happening between your frontend and your Built-in Agent:
20-
21-
| Panel | What you see |
22-
| --- | --- |
23-
| **AG-UI Events** | The raw event stream between the runtime and your agent, in real time — including `RUN_STARTED`, `TEXT_MESSAGE_CONTENT`, `TOOL_CALL_*`, `STATE_SNAPSHOT`, and any custom events. |
24-
| **Available Agents** | Which agents CopilotKit has discovered via `/info` and which one is currently active. |
25-
| **Agent State** | The current `agent.state` tree, rerendered as it updates. Great for debugging [shared state](./shared-state) flows. |
26-
| **Frontend Tools** | Every tool registered via `useFrontendTool`, `useComponent`, `useHumanInTheLoop`, or `useRenderTool`, along with its parameter schema. |
27-
| **Context** | The [`useAgentContext`](/langgraph-python/agent-app-context) entries the agent currently receives, plus any document context you've attached. |
28-
29-
## When should I use it?
30-
31-
Reach for the inspector when:
32-
33-
- Your agent seems to ignore a tool you registered — check the **Frontend Tools** panel to confirm the registration landed.
34-
- A chat response looks "stuck" — the **AG-UI Events** panel shows exactly which event type arrived last.
35-
- You think state isn't syncing — the **Agent State** panel updates on every `onStateSnapshotEvent` / `onStateDeltaEvent`.
36-
- You want to confirm the Built-in Agent is reading the correct `useAgentContext` value.
37-
38-
## Getting a license key
39-
40-
The inspector is a **premium** feature. Grab a **free** `publicLicenseKey` at [https://cloud.copilotkit.ai](https://cloud.copilotkit.ai) and pass it to your provider:
41-
42-
```tsx title="app/layout.tsx"
43-
import { CopilotKitProvider } from "@copilotkit/react-core/v2";
44-
45-
export default function RootLayout({ children }) {
46-
return (
47-
<CopilotKitProvider
48-
runtimeUrl="/api/copilotkit"
49-
publicLicenseKey={process.env.NEXT_PUBLIC_COPILOTKIT_LICENSE_KEY}
50-
>
51-
{children}
52-
</CopilotKitProvider>
53-
);
54-
}
55-
```
56-
57-
The inspector is enabled by default whenever a valid license key is present.
58-
59-
## Disabling it
60-
61-
Sometimes you want the license key (for other premium features) but not the inspector overlay:
62-
63-
```tsx
64-
<CopilotKitProvider
65-
publicLicenseKey={process.env.NEXT_PUBLIC_COPILOTKIT_LICENSE_KEY}
66-
enableInspector={false}
67-
>
68-
{children}
69-
</CopilotKitProvider>
70-
```
6+
<Inspector />
717

728
<Callout type="info">
73-
The inspector is **automatically disabled in production builds**. You don't need to guard it behind `process.env.NODE_ENV` or strip it manually — production bundles ship without the overlay code.
9+
Want to preview A2UI catalog components directly in your editor? See the [VS Code Extension](/vs-code-extension)
10+
for live preview with hot-reload.
7411
</Callout>
75-
76-
## Related
77-
78-
- [Debug mode](./troubleshooting/error-debugging) — console logging for the same event pipeline without a UI overlay.
79-
- [Observability](./premium/observability) — production-grade event + error hooks for Sentry, Datadog, and analytics.

showcase/shell-docs/src/content/docs/integrations/agent-spec/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ hideTOC: true
334334
Wrap your application with the CopilotKit provider:
335335
336336
```tsx title="app/layout.tsx"
337-
import { CopilotKit } from "@copilotkit/react-core/v2"; // [!code highlight]
337+
import { CopilotKit } from "@copilotkit/react-core"; // [!code highlight]
338338
import "@copilotkit/react-ui/v2/styles.css";
339339
import './globals.css';
340340
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: AWS AgentCore
3+
icon: "lucide/Cloud"
4+
description: Add a production-ready frontend to your AWS AgentCore agents with CopilotKit.
5+
hideHeader: true
6+
---
7+
<Content framework="strands" />

showcase/shell-docs/src/content/docs/integrations/aws-strands/quickstart.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ Before you begin, you'll need the following:
350350

351351
</Steps>
352352

353+
## Deploying to AWS?
354+
355+
If you're planning to deploy your Strands agent to AWS Bedrock AgentCore, see the [AgentCore deploy guide](/agentcore).
356+
353357
## What's next?
354358

355359
Now that you have your basic agent setup, explore these advanced features:

showcase/shell-docs/src/content/docs/integrations/built-in-agent/server-tools.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const getWeather = defineTool({
3434
const builtInAgent = new BuiltInAgent({
3535
model: "openai:gpt-5.4-mini",
3636
tools: [getWeather],
37-
maxSteps: 2, // Important for tool calls
37+
maxSteps: 2 //Important for tool calls
3838
});
3939
```
4040

@@ -76,7 +76,7 @@ const createTicket = defineTool({
7676
const builtInAgent = new BuiltInAgent({
7777
model: "openai:gpt-5.4-mini",
7878
tools: [searchDocs, createTicket], // [!code highlight]
79-
maxSteps: 2,
79+
maxSteps: 2
8080
});
8181
```
8282

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: Frontend Tools
3+
icon: "lucide/Wrench"
4+
description: Create frontend tools and use them within your Deep Agents agent.
5+
hideTOC: true
6+
---
7+
{/* TODO: swap feature-viewer URLs back to /deepagents/ once the dojo supports that route */}
8+
<IframeSwitcher
9+
id="frontend-actions-example"
10+
exampleUrl="https://feature-viewer.copilotkit.ai/langgraph/feature/agentic_chat?sidebar=false&chatDefaultOpen=false"
11+
codeUrl="https://feature-viewer.copilotkit.ai/langgraph/feature/agentic_chat?view=code&sidebar=false&codeLayout=tabs"
12+
exampleLabel="Demo"
13+
codeLabel="Code"
14+
height="700px"
15+
/>
16+
17+
## What is this?
18+
Frontend tools enable you to define client-side functions that your Deep Agents agent can invoke, with execution happening entirely in the user's browser. When your agent calls a frontend tool,
19+
the logic runs on the client side, giving you direct access to the frontend environment.
20+
21+
This can be utilized to let your agent control the UI, for generative UI, or for Human-in-the-loop interactions.
22+
23+
In this guide, we cover the use of frontend tools driving and interacting with the UI.
24+
25+
## When should I use this?
26+
Use frontend tools when you need your agent to interact with client-side primitives such as:
27+
- Reading or modifying React component state
28+
- Accessing browser APIs like localStorage, sessionStorage, or cookies
29+
- Triggering UI updates or animations
30+
- Interacting with third-party frontend libraries
31+
- Performing actions that require the user's immediate browser context
32+
33+
## Implementation
34+
35+
<Steps>
36+
<Step>
37+
### Run and connect your agent
38+
<RunAndConnect />
39+
</Step>
40+
41+
<Step>
42+
### Create a frontend tool
43+
44+
First, you'll need to create a frontend tool using the [useFrontendTool](/reference/v2/hooks/useFrontendTool) hook. Here's a simple one to get you started
45+
that says hello to the user.
46+
47+
```tsx title="page.tsx"
48+
import { z } from "zod";
49+
import { useFrontendTool } from "@copilotkit/react-core/v2" // [!code highlight]
50+
51+
export function Page() {
52+
// ...
53+
54+
// [!code highlight:12]
55+
useFrontendTool({
56+
name: "sayHello",
57+
description: "Say hello to the user",
58+
parameters: z.object({
59+
name: z.string().describe("The name of the user to say hello to"),
60+
}),
61+
handler: async ({ name }) => {
62+
alert(`Hello, ${name}!`);
63+
return `Said hello to ${name}!`;
64+
},
65+
});
66+
67+
// ...
68+
}
69+
```
70+
</Step>
71+
<Step>
72+
### Install the CopilotKit SDK
73+
74+
Now, we'll need to modify the agent to access these frontend tools. In your terminal, navigate to your agent's folder and continue from there!
75+
76+
<InstallSDKSnippet/>
77+
</Step>
78+
<Step>
79+
### Wire CopilotKit state into your agent
80+
81+
To access the frontend tools provided by CopilotKit, register the CopilotKit state alongside any custom state your agent needs.
82+
83+
<Tabs groupId="agent_language" items={['Python', 'TypeScript']} persist>
84+
<Tab value="Python">
85+
In Python, inherit from `CopilotKitState` in your agent's state definition:
86+
87+
```python title="agent.py"
88+
from copilotkit import CopilotKitState # [!code highlight]
89+
90+
class YourAgentState(CopilotKitState): # [!code highlight]
91+
your_additional_properties: str
92+
```
93+
</Tab>
94+
<Tab value="TypeScript">
95+
In TypeScript, define your custom state as a middleware via `createMiddleware` and compose it with `copilotkitMiddleware`:
96+
97+
```ts title="agent.ts"
98+
import { createMiddleware } from "langchain";
99+
import { copilotkitMiddleware } from "@copilotkit/sdk-js/langgraph"; // [!code highlight]
100+
import { z } from "zod";
101+
102+
export const yourStateMiddleware = createMiddleware({
103+
name: "YourAgentState",
104+
stateSchema: z.object({
105+
yourAdditionalProperty: z.string().optional(),
106+
}),
107+
});
108+
109+
// Pass both middlewares when constructing the agent:
110+
// createDeepAgent({ middleware: [yourStateMiddleware, copilotkitMiddleware], ... })
111+
```
112+
</Tab>
113+
</Tabs>
114+
115+
By doing this, your agent's state will include the `copilotkit` property, which contains the frontend tools that can be accessed and invoked.
116+
</Step>
117+
<Step>
118+
### Accessing Frontend Tools
119+
120+
Once your agent's state includes the `copilotkit` property, you can access the frontend tools and utilize them within your agent's logic.
121+
122+
Here's how you can call a frontend tool from your agent:
123+
124+
<FrontEndToolsImpl />
125+
126+
These tools are automatically populated by CopilotKit and are compatible with LangChain's tool call definitions, making it straightforward to integrate them into your agent's workflow.
127+
</Step>
128+
<Step>
129+
### Give it a try!
130+
You've now given your agent the ability to directly call any frontend tools you've defined. These tools will be available to the agent where they can be used as needed.
131+
132+
<video src="https://cdn.copilotkit.ai/docs/copilotkit/images/frontend-actions-demo.mp4" className="rounded-lg shadow-xl" loop playsInline controls autoPlay muted />
133+
</Step>
134+
</Steps>

0 commit comments

Comments
 (0)