Skip to content

Commit 23af690

Browse files
committed
fix(examples): migrate integrations from v1 to v2 API surface
Migrate 15 example integrations from the v1 compatibility facade to native v2 CopilotKit APIs. The v1 surface delegates to v2 internally so this is an API surface change, not a functional one. Key changes per integration: - Import paths: @copilotkit/react-core -> react-core/v2, @copilotkit/runtime -> runtime/v2 - Hook renames: useCoAgent -> useAgent, useCopilotAction -> useFrontendTool, useRenderToolCall -> useRenderTool - UI: CopilotSidebar from react-ui -> react-core/v2 - Styles: react-ui/styles.css -> react-core/v2/styles.css - Runtime: copilotRuntimeNextJSAppRouterEndpoint -> createCopilotEndpoint + hono/vercel - Removed @copilotkit/react-ui and @copilotkit/shared deps Integrations migrated (v1 -> v2): a2a-middleware, adk, agno, crewai-crews, crewai-flows, langgraph-js, llamaindex, mastra, ms-agent-framework-dotnet, ms-agent-framework-python, pydantic-ai, strands-python Mixed integrations cleaned up (stale deps removed): agent-spec, agentcore, langgraph-fastapi, langgraph-python, langgraph-python-threads
1 parent a30be17 commit 23af690

62 files changed

Lines changed: 478 additions & 522 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/integrations/a2a-middleware/app/api/copilotkit/route.ts renamed to examples/integrations/a2a-middleware/app/api/copilotkit/[[...slug]]/route.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
1-
/**
2-
* CopilotKit API Route with A2A Middleware
3-
*
4-
* This connects the frontend to multiple agents using two protocols:
5-
* - AG-UI Protocol: Frontend ↔ Orchestrator (via CopilotKit)
6-
* - A2A Protocol: Orchestrator ↔ Specialized Agents (Research, Analysis)
7-
*
8-
* The A2A middleware injects send_message_to_a2a_agent tool into the orchestrator,
9-
* enabling seamless agent-to-agent communication without the orchestrator needing
10-
* to understand A2A Protocol directly.
11-
*/
12-
131
import {
142
CopilotRuntime,
15-
ExperimentalEmptyAdapter,
16-
copilotRuntimeNextJSAppRouterEndpoint,
17-
} from "@copilotkit/runtime";
3+
createCopilotEndpoint,
4+
InMemoryAgentRunner,
5+
} from "@copilotkit/runtime/v2";
186
import { HttpAgent } from "@ag-ui/client";
197
import { A2AMiddlewareAgent } from "@ag-ui/a2a-middleware";
20-
import { NextRequest } from "next/server";
8+
import { handle } from "hono/vercel";
219

22-
export async function POST(request: NextRequest) {
10+
export async function POST(request: Request) {
2311
const researchAgentUrl =
2412
process.env.RESEARCH_AGENT_URL || "http://localhost:9001";
2513
const analysisAgentUrl =
2614
process.env.ANALYSIS_AGENT_URL || "http://localhost:9002";
2715
const orchestratorUrl =
2816
process.env.ORCHESTRATOR_URL || "http://localhost:9000";
2917

30-
// Connect to orchestrator via AG-UI Protocol
3118
const orchestrationAgent = new HttpAgent({
3219
url: orchestratorUrl,
3320
});
3421

35-
// A2A Middleware: Wraps orchestrator and injects send_message_to_a2a_agent tool
36-
// This allows orchestrator to communicate with A2A agents transparently
3722
const a2aMiddlewareAgent = new A2AMiddlewareAgent({
3823
description:
3924
"Research assistant with 2 specialized agents: Research (LangGraph) and Analysis (ADK)",
@@ -68,18 +53,29 @@ export async function POST(request: NextRequest) {
6853
`,
6954
});
7055

71-
// CopilotKit runtime connects frontend to agent system
7256
const runtime = new CopilotRuntime({
7357
agents: {
74-
a2a_chat: a2aMiddlewareAgent, // Must match agent prop in <CopilotKit agent="a2a_chat">
58+
a2a_chat: a2aMiddlewareAgent,
7559
},
60+
runner: new InMemoryAgentRunner(),
7661
});
7762

78-
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
63+
const app = createCopilotEndpoint({
7964
runtime,
80-
serviceAdapter: new ExperimentalEmptyAdapter(),
81-
endpoint: "/api/copilotkit",
65+
basePath: "/api/copilotkit",
8266
});
8367

84-
return handleRequest(request);
68+
return handle(app)(request);
69+
}
70+
71+
export async function GET(request: Request) {
72+
const runtime = new CopilotRuntime({
73+
agents: {},
74+
runner: new InMemoryAgentRunner(),
75+
});
76+
const app = createCopilotEndpoint({
77+
runtime,
78+
basePath: "/api/copilotkit",
79+
});
80+
return handle(app)(request);
8581
}

examples/integrations/a2a-middleware/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Metadata } from "next";
22
import { Plus_Jakarta_Sans, Spline_Sans_Mono } from "next/font/google";
33
import "./globals.css";
4-
import "@copilotkit/react-ui/styles.css";
4+
import "@copilotkit/react-core/v2/styles.css";
55

66
const plusJakartaSans = Plus_Jakarta_Sans({
77
variable: "--font-plus-jakarta-sans",

examples/integrations/a2a-middleware/components/chat.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import React, { useEffect } from "react";
99
import {
1010
CopilotKit,
11-
useCopilotChat,
12-
useCopilotAction,
13-
} from "@copilotkit/react-core";
14-
import { CopilotChat } from "@copilotkit/react-ui";
15-
import "@copilotkit/react-ui/styles.css";
11+
useFrontendTool,
12+
CopilotChat,
13+
} from "@copilotkit/react-core/v2";
14+
// NOTE: useCopilotChat has no v2 equivalent; kept on v1 import path
15+
import { useCopilotChat } from "@copilotkit/react-core";
16+
import "@copilotkit/react-core/v2/styles.css";
1617
import { MessageToA2A } from "./a2a/MessageToA2A";
1718
import { MessageFromA2A } from "./a2a/MessageFromA2A";
1819

@@ -84,7 +85,7 @@ const ChatInner = ({ onResearchUpdate, onAnalysisUpdate }: ChatProps) => {
8485
}, [visibleMessages, onResearchUpdate, onAnalysisUpdate]);
8586

8687
// Register action to render A2A message flow visualization
87-
useCopilotAction({
88+
useFrontendTool({
8889
name: "send_message_to_a2a_agent",
8990
description: "Sends a message to an A2A agent",
9091
available: "frontend",

examples/integrations/a2a-middleware/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"@ag-ui/a2a-middleware": "0.0.2",
1919
"@ag-ui/client": "0.0.52",
2020
"@copilotkit/react-core": "latest",
21-
"@copilotkit/react-ui": "latest",
2221
"@copilotkit/runtime": "latest",
22+
"hono": "^4",
2323
"next": "15.5.15",
2424
"react": "^19.0.0",
2525
"react-dom": "^19.0.0"

examples/integrations/adk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"dependencies": {
1616
"@ag-ui/client": "0.0.52",
1717
"@copilotkit/react-core": "1.56.4",
18-
"@copilotkit/react-ui": "1.56.4",
1918
"@copilotkit/runtime": "1.56.4",
19+
"@hono/node-server": "^1",
20+
"hono": "^4",
2021
"next": "16.1.1",
2122
"react": "^19.2.1",
2223
"react-dom": "^19.2.1",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
CopilotRuntime,
3+
createCopilotEndpoint,
4+
InMemoryAgentRunner,
5+
} from "@copilotkit/runtime/v2";
6+
import { HttpAgent } from "@ag-ui/client";
7+
import { handle } from "hono/vercel";
8+
9+
const runtime = new CopilotRuntime({
10+
agents: {
11+
my_agent: new HttpAgent({
12+
url: process.env.AGENT_URL || "http://localhost:8000/",
13+
}),
14+
},
15+
runner: new InMemoryAgentRunner(),
16+
});
17+
18+
const app = createCopilotEndpoint({
19+
runtime,
20+
basePath: "/api/copilotkit",
21+
});
22+
23+
export const GET = handle(app);
24+
export const POST = handle(app);

examples/integrations/adk/src/app/api/copilotkit/route.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/integrations/adk/src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Metadata } from "next";
22

3-
import { CopilotKit } from "@copilotkit/react-core";
3+
import { CopilotKit } from "@copilotkit/react-core/v2";
44
import "./globals.css";
5-
import "@copilotkit/react-ui/styles.css";
5+
import "@copilotkit/react-core/v2/styles.css";
66

77
export const metadata: Metadata = {
88
title: "Create Next App",

examples/integrations/adk/src/app/page.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { ProverbsCard } from "@/components/proverbs";
44
import { WeatherCard } from "@/components/weather";
55
import { AgentState } from "@/lib/types";
66
import {
7-
useCoAgent,
8-
useDefaultTool,
7+
useAgent,
8+
useDefaultRenderTool,
99
useFrontendTool,
1010
useHumanInTheLoop,
11-
useRenderToolCall,
12-
} from "@copilotkit/react-core";
13-
import { CopilotKitCSSProperties, CopilotSidebar } from "@copilotkit/react-ui";
14-
import { useState } from "react";
11+
useRenderTool,
12+
CopilotSidebar,
13+
} from "@copilotkit/react-core/v2";
14+
import React, { useState } from "react";
1515

1616
export default function CopilotKitPage() {
1717
const [themeColor, setThemeColor] = useState("#6366f1");
@@ -34,7 +34,7 @@ export default function CopilotKitPage() {
3434
return (
3535
<main
3636
style={
37-
{ "--copilot-kit-primary-color": themeColor } as CopilotKitCSSProperties
37+
{ "--copilot-kit-primary-color": themeColor } as React.CSSProperties
3838
}
3939
>
4040
<CopilotSidebar
@@ -77,23 +77,18 @@ export default function CopilotKitPage() {
7777

7878
function YourMainContent({ themeColor }: { themeColor: string }) {
7979
// 🪁 Shared State: https://docs.copilotkit.ai/adk/shared-state
80-
const { state, setState } = useCoAgent<AgentState>({
81-
name: "my_agent",
82-
initialState: {
83-
proverbs: [
84-
"CopilotKit may be new, but its the best thing since sliced bread.",
85-
],
86-
},
80+
const { agent } = useAgent({
81+
agentId: "my_agent",
8782
});
83+
const state = (agent.state ?? { proverbs: ["CopilotKit may be new, but its the best thing since sliced bread."] }) as AgentState;
84+
const setState = (newState: AgentState) => agent.setState(newState);
8885

8986
//🪁 Generative UI: https://docs.copilotkit.ai/adk/generative-ui
90-
useRenderToolCall(
87+
useRenderTool(
9188
{
9289
name: "get_weather",
93-
description: "Get the weather for a given location.",
94-
parameters: [{ name: "location", type: "string", required: true }],
95-
render: ({ args, result }) => {
96-
return <WeatherCard location={args.location} themeColor={themeColor} />;
90+
render: ({ parameters, result }) => {
91+
return <WeatherCard location={(parameters as any)?.location} themeColor={themeColor} />;
9792
},
9893
},
9994
[themeColor],

examples/integrations/agent-spec/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
"@ag-ui/proto": "^0.0.46",
2424
"@copilotkit/a2ui-renderer": "1.57.1",
2525
"@copilotkit/react-core": "1.57.1",
26-
"@copilotkit/react-ui": "1.57.1",
2726
"@copilotkit/runtime": "1.57.1",
28-
"@copilotkit/runtime-client-gql": "1.57.1",
29-
"@copilotkit/shared": "1.57.1",
3027
"hono": "^4.11.4",
3128
"next": "16.0.10",
3229
"react": "^19.2.3",

0 commit comments

Comments
 (0)