Skip to content

Commit 1197844

Browse files
committed
feat: support copilotkit vnext
Signed-off-by: Tyler Slaton <[email protected]>
1 parent 2170f41 commit 1197844

File tree

9 files changed

+191
-269
lines changed

9 files changed

+191
-269
lines changed

agent/poetry.lock

Lines changed: 10 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package-mode = false
99

1010
[tool.poetry.dependencies]
1111
python = ">=3.10,<3.13"
12-
copilotkit = "0.1.55"
12+
ag-ui-langgraph = "0.0.18a0"
1313
langchain = "0.3.26"
1414
langchain-openai = "0.3.28"
1515
langgraph = "0.4.10"

agent/sample_agent/demo.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55

66
import os
77
from dotenv import load_dotenv
8-
load_dotenv() # pylint: disable=wrong-import-position
98

109
from fastapi import FastAPI
1110
import uvicorn
12-
from copilotkit import LangGraphAGUIAgent
1311
from sample_agent.agent import graph
14-
from ag_ui_langgraph import add_langgraph_fastapi_endpoint
12+
from ag_ui_langgraph import add_langgraph_fastapi_endpoint, LangGraphAgent
13+
14+
_ = load_dotenv() # pylint: disable=wrong-import-position
1515

1616
app = FastAPI()
1717

1818
add_langgraph_fastapi_endpoint(
1919
app=app,
20-
agent=LangGraphAGUIAgent(
20+
agent=LangGraphAgent(
2121
name="sample_agent",
2222
description="An example agent to use as a starting point for your own agent.",
23-
graph=graph
23+
graph=graph,
2424
),
25-
path="/"
25+
path="/",
2626
)
2727

28+
2829
def main():
2930
"""Run the uvicorn server."""
3031
port = int(os.getenv("PORT", "8123"))

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
"install:agent": "cd agent && poetry install"
1414
},
1515
"dependencies": {
16-
"@ag-ui/langgraph": "0.0.6",
17-
"@ai-sdk/openai": "^1.3.22",
18-
"@copilotkit/react-core": "1.9.2",
19-
"@copilotkit/react-ui": "1.9.2",
20-
"@copilotkit/runtime": "1.9.2",
16+
"@ag-ui/core": "0.0.40-alpha.7",
17+
"@ag-ui/langgraph": "0.0.19-alpha.1",
18+
"@copilotkitnext/core": "0.0.19-threads-and-attachements.1",
19+
"@copilotkitnext/react": "0.0.19-threads-and-attachements.1",
20+
"@copilotkitnext/runtime": "0.0.19-threads-and-attachements.1",
21+
"hono": "^4.10.1",
2122
"next": "15.3.2",
2223
"react": "^19.0.0",
2324
"react-dom": "^19.0.0",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { LangGraphHttpAgent } from "@ag-ui/langgraph";
2+
import {
3+
CopilotRuntime,
4+
createCopilotEndpoint,
5+
AgentRunner,
6+
} from "@copilotkitnext/runtime";
7+
import { handle } from "hono/vercel";
8+
9+
const runtime = new CopilotRuntime({
10+
agents: {
11+
default: new LangGraphHttpAgent({
12+
url: process.env.AGENT_URL || "http://localhost:8123",
13+
}),
14+
foo: new LangGraphHttpAgent({
15+
url: process.env.AGENT_URL || "http://localhost:8123",
16+
}),
17+
},
18+
});
19+
20+
const app = createCopilotEndpoint({
21+
runtime,
22+
basePath: "/api/copilotkit",
23+
});
24+
25+
export const GET = handle(app);
26+
export const POST = handle(app);

src/app/api/copilotkit/route.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"use client";
2+
3+
// Weather card component where the location and themeColor are based on what the agent
4+
// sets via tool calls.
5+
6+
import { defineToolCallRenderer } from "@copilotkitnext/react";
7+
8+
// @ts-ignore
9+
export const weatherToolRenderer = defineToolCallRenderer({
10+
name: "get_weather",
11+
render: ({ args }) => {
12+
const { location } = args;
13+
const themeColor = "blue";
14+
return <WeatherCard location={location} themeColor={themeColor} />;
15+
},
16+
});
17+
18+
function WeatherCard({
19+
location,
20+
themeColor,
21+
}: {
22+
location?: string;
23+
themeColor: string;
24+
}) {
25+
return (
26+
<div
27+
style={{ backgroundColor: themeColor }}
28+
className="rounded-xl shadow-xl mt-6 mb-4 max-w-md w-full"
29+
>
30+
<div className="bg-white/20 p-4 w-full">
31+
<div className="flex items-center justify-between">
32+
<div>
33+
<h3 className="text-xl font-bold text-white capitalize">
34+
{location}
35+
</h3>
36+
<p className="text-white">Current Weather</p>
37+
</div>
38+
<SunIcon />
39+
</div>
40+
41+
<div className="mt-4 flex items-end justify-between">
42+
<div className="text-3xl font-bold text-white">70°</div>
43+
<div className="text-sm text-white">Clear skies</div>
44+
</div>
45+
46+
<div className="mt-4 pt-4 border-t border-white">
47+
<div className="grid grid-cols-3 gap-2 text-center">
48+
<div>
49+
<p className="text-white text-xs">Humidity</p>
50+
<p className="text-white font-medium">45%</p>
51+
</div>
52+
<div>
53+
<p className="text-white text-xs">Wind</p>
54+
<p className="text-white font-medium">5 mph</p>
55+
</div>
56+
<div>
57+
<p className="text-white text-xs">Feels Like</p>
58+
<p className="text-white font-medium">72°</p>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
</div>
64+
);
65+
}
66+
67+
// Simple sun icon for the weather card
68+
function SunIcon() {
69+
return (
70+
<svg
71+
xmlns="http://www.w3.org/2000/svg"
72+
viewBox="0 0 24 24"
73+
fill="currentColor"
74+
className="w-14 h-14 text-yellow-200"
75+
>
76+
<circle cx="12" cy="12" r="5" />
77+
<path
78+
d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"
79+
strokeWidth="2"
80+
stroke="currentColor"
81+
/>
82+
</svg>
83+
);
84+
}

src/app/layout.tsx

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

3-
import { CopilotKit } from "@copilotkit/react-core";
3+
import { CopilotKitProvider } from "@copilotkitnext/react";
44
import "./globals.css";
5-
import "@copilotkit/react-ui/styles.css";
5+
import "@copilotkitnext/react/styles.css";
6+
import { weatherToolRenderer } from "./components/gen-ui/weather";
67

78
export const metadata: Metadata = {
89
title: "Create Next App",
@@ -17,9 +18,12 @@ export default function RootLayout({
1718
return (
1819
<html lang="en">
1920
<body className={"antialiased"}>
20-
<CopilotKit runtimeUrl="/api/copilotkit" agent="sample_agent">
21+
<CopilotKitProvider
22+
renderToolCalls={[weatherToolRenderer]}
23+
runtimeUrl="/api/copilotkit"
24+
>
2125
{children}
22-
</CopilotKit>
26+
</CopilotKitProvider>
2327
</body>
2428
</html>
2529
);

0 commit comments

Comments
 (0)