From 74e63a6b9adea45378d550fe263e7c6da3c8569a Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Sat, 13 Dec 2025 00:35:38 +0100 Subject: [PATCH] fix web errors --- web/agent/pyproject.toml | 1 + web/agent/server.py | 39 +++++++++-------------------- web/src/app/api/copilotkit/route.ts | 11 ++++---- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/web/agent/pyproject.toml b/web/agent/pyproject.toml index d12980c..39d5173 100644 --- a/web/agent/pyproject.toml +++ b/web/agent/pyproject.toml @@ -16,4 +16,5 @@ dependencies = [ "docstring-parser>=0.17.0", "jsonschema>=4.25.1", "copilotkit>=0.1.0", + "ag-ui-langgraph>=0.0.4", ] diff --git a/web/agent/server.py b/web/agent/server.py index a191327..260fd8f 100644 --- a/web/agent/server.py +++ b/web/agent/server.py @@ -1,5 +1,5 @@ """ -Self-hosted LangGraph agent server using CopilotKit. +Self-hosted LangGraph agent server using CopilotKit AG-UI protocol. """ import os @@ -7,38 +7,23 @@ from fastapi import FastAPI import uvicorn from dotenv import load_dotenv -from copilotkit import CopilotKitRemoteEndpoint, LangGraphAgent -from copilotkit.integrations.fastapi import add_fastapi_endpoint +from copilotkit import LangGraphAGUIAgent +from ag_ui_langgraph import add_langgraph_fastapi_endpoint from main import graph load_dotenv() app = FastAPI(title="Cavepedia Agent") - -def build_agents(context): - """Build agents with auth context from properties.""" - # Get user roles from frontend properties - user_roles = context.get("properties", {}).get("auth0_user_roles", []) - - return [ - LangGraphAgent( - name="vpi_1000", - description="AI assistant with access to cave-related information through the Cavepedia MCP server", - graph=graph, - langgraph_config={ - "configurable": { - "context": { - "auth0_user_roles": user_roles, - } - } - }, - ) - ] - - -sdk = CopilotKitRemoteEndpoint(agents=build_agents) -add_fastapi_endpoint(app, sdk, "/copilotkit") +add_langgraph_fastapi_endpoint( + app=app, + agent=LangGraphAGUIAgent( + name="vpi_1000", + description="AI assistant with access to cave-related information through the Cavepedia MCP server", + graph=graph, + ), + path="/", +) @app.get("/health") diff --git a/web/src/app/api/copilotkit/route.ts b/web/src/app/api/copilotkit/route.ts index 4b05cd1..121ec29 100644 --- a/web/src/app/api/copilotkit/route.ts +++ b/web/src/app/api/copilotkit/route.ts @@ -2,7 +2,6 @@ import { CopilotRuntime, ExperimentalEmptyAdapter, copilotRuntimeNextJSAppRouterEndpoint, - LangGraphHttpAgent, } from "@copilotkit/runtime"; import { NextRequest } from "next/server"; @@ -10,11 +9,11 @@ import { NextRequest } from "next/server"; const serviceAdapter = new ExperimentalEmptyAdapter(); const runtime = new CopilotRuntime({ - agents: { - vpi_1000: new LangGraphHttpAgent({ - url: `${process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8000"}/copilotkit`, - }), - }, + remoteEndpoints: [ + { + url: process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8000", + }, + ], }); export const POST = async (req: NextRequest) => {