#httpAgent on nextjs example
1 messages · Page 1 of 1 (latest)
This solution has been AI generated
Here's a minimal Next.js API route using HttpAgent. It forwards requests from your Next.js app to a remote agent endpoint that speaks the AG‑UI protocol.
Example: Next.js App Router (app/api/copilotkit/route.ts)
import { NextRequest } from "next/server";
import {
CopilotRuntime,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { HttpAgent } from "@ag-ui/client";
const runtime = new CopilotRuntime({
agents: {
my_agent: new HttpAgent({
url: process.env.REMOTE_AGENT_URL || "http://localhost:8000/agui",
}),
},
});
export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter: /* adapter here, e.g., OpenAIAdapter */ undefined,
endpoint: req.nextUrl.pathname,
});
return handleRequest(req);
};
Notes
- Environment variables: set
REMOTE_AGENT_URLfor dev/prod (e.g.,http://localhost:8000/agui). - Protocol compatibility: ensure your backend agent is configured to accept AG‑UI (e.g., via
.to_ag_ui()helpers on Python backends). - Dependencies: install
@copilotkit/runtimeand@ag-ui/client. - Adapter: provide a
serviceAdaptersuited to your model provider if needed.
Was this helpful?
If this solution worked for you, please click on the appropriate option below to help us improve: