This commit is contained in:
2025-12-07 20:25:53 -07:00
parent 96dd462043
commit fbb050056f
2 changed files with 76 additions and 42 deletions

View File

@@ -6,30 +6,43 @@ import {
import { LangGraphAgent } from "@ag-ui/langgraph"
import { NextRequest } from "next/server";
import { auth0 } from "@/lib/auth0";
// 1. You can use any service adapter here for multi-agent support. We use
// the empty adapter since we're only using one agent.
const serviceAdapter = new ExperimentalEmptyAdapter();
// 2. Create the CopilotRuntime instance and utilize the LangGraph AG-UI
// integration to setup the connection.
const runtime = new CopilotRuntime({
agents: {
"sample_agent": new LangGraphAgent({
deploymentUrl: process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8123",
graphId: "sample_agent",
langsmithApiKey: process.env.LANGSMITH_API_KEY || "",
}),
}
});
// 3. Build a Next.js API route that handles the CopilotKit runtime requests.
export const POST = async (req: NextRequest) => {
// Get Auth0 session
const session = await auth0.getSession();
// Extract access token and roles from session
const accessToken = session?.accessToken;
const userRoles = session?.user?.roles || [];
// 2. Create the CopilotRuntime instance with Auth0 configuration
const runtime = new CopilotRuntime({
agents: {
"sample_agent": new LangGraphAgent({
deploymentUrl: process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8123",
graphId: "sample_agent",
langsmithApiKey: process.env.LANGSMITH_API_KEY || "",
langgraphConfig: {
configurable: {
auth0_access_token: accessToken,
auth0_user_roles: userRoles,
}
}
}),
}
});
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
runtime,
serviceAdapter,
endpoint: "/api/copilotkit",
});
return handleRequest(req);
};