Skip to content

Commit a2de25a

Browse files
committed
fix: use LangGraphAgent for LangGraph Platform, LangGraphHttpAgent for self-hosted
LangGraphHttpAgent speaks the AG-UI HTTP protocol which only the self-hosted FastAPI server exposes. LangGraph Platform uses a different API, causing 404s. Switch to LangGraphAgent (native LangGraph SDK) when LANGSMITH_API_KEY is set, keeping LangGraphHttpAgent for local dev.
1 parent c933e3a commit a2de25a

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

apps/app/src/app/api/copilotkit/route.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ExperimentalEmptyAdapter,
44
copilotRuntimeNextJSAppRouterEndpoint,
55
} from "@copilotkit/runtime";
6-
import { LangGraphHttpAgent } from "@copilotkit/runtime/langgraph";
6+
import { LangGraphAgent, LangGraphHttpAgent } from "@copilotkit/runtime/langgraph";
77
import { NextRequest } from "next/server";
88

99
// Simple in-memory sliding-window rate limiter (per IP)
@@ -44,12 +44,18 @@ const deploymentUrl = !raw
4444
: `http://${raw}`;
4545

4646
// 1. Define the agent connection to LangGraph
47-
const defaultAgent = new LangGraphHttpAgent({
48-
url: deploymentUrl,
49-
...(process.env.LANGSMITH_API_KEY && {
50-
headers: { "x-api-key": process.env.LANGSMITH_API_KEY },
51-
}),
52-
});
47+
// LangGraphAgent talks the native LangGraph SDK API (for LangGraph Platform / Cloud).
48+
// LangGraphHttpAgent talks the AG-UI HTTP protocol (for self-hosted FastAPI server).
49+
const usePlatform = !!process.env.LANGSMITH_API_KEY;
50+
const defaultAgent = usePlatform
51+
? new LangGraphAgent({
52+
deploymentUrl: deploymentUrl,
53+
graphId: "sample_agent",
54+
langsmithApiKey: process.env.LANGSMITH_API_KEY,
55+
})
56+
: new LangGraphHttpAgent({
57+
url: deploymentUrl,
58+
});
5359

5460
// 3. Define the route and CopilotRuntime for the agent
5561
export const POST = async (req: NextRequest) => {

0 commit comments

Comments
 (0)