self-host langgraph
Some checks failed
Build and Push Agent Docker Image / build (push) Successful in 1m7s
Build and Push Web Docker Image / build (push) Failing after 3m5s

This commit is contained in:
2025-12-13 00:05:06 +01:00
parent 0ff215c34f
commit 17802994a5
5 changed files with 43 additions and 33 deletions

View File

@@ -22,15 +22,12 @@ jobs:
username: ${{ gitea.actor }} username: ${{ gitea.actor }}
password: ${{ secrets.ACTIONS_PUSH_TOKEN }} password: ${{ secrets.ACTIONS_PUSH_TOKEN }}
- name: Install uv - name: Set up Docker Buildx
run: | uses: docker/setup-buildx-action@v3
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Build with langgraph - name: Build and push
working-directory: ./web/agent uses: docker/build-push-action@v6
run: | with:
uv run langgraph build -t git.seaturtle.pw/cavepedia/cavepediav2-agent:latest context: ./web/agent
push: true
- name: Push image tags: git.seaturtle.pw/cavepedia/cavepediav2-agent:latest
run: docker push git.seaturtle.pw/cavepedia/cavepediav2-agent:latest

View File

@@ -16,5 +16,4 @@ dependencies = [
"docstring-parser>=0.17.0", "docstring-parser>=0.17.0",
"jsonschema>=4.25.1", "jsonschema>=4.25.1",
"copilotkit>=0.1.0", "copilotkit>=0.1.0",
"ag-ui-langgraph>=0.0.4",
] ]

View File

@@ -1,5 +1,5 @@
""" """
Self-hosted LangGraph agent server using CopilotKit's AG-UI protocol. Self-hosted LangGraph agent server using CopilotKit.
""" """
import os import os
@@ -7,23 +7,36 @@ from fastapi import FastAPI
import uvicorn import uvicorn
from dotenv import load_dotenv from dotenv import load_dotenv
from copilotkit import LangGraphAGUIAgent from copilotkit import CopilotKitRemoteEndpoint, LangGraphAgent
from ag_ui_langgraph import add_langgraph_fastapi_endpoint from copilotkit.integrations.fastapi import add_fastapi_endpoint
from main import graph from main import graph
load_dotenv() load_dotenv()
app = FastAPI(title="Cavepedia Agent") app = FastAPI(title="Cavepedia Agent")
add_langgraph_fastapi_endpoint(
app=app, def build_agents(context):
agent=LangGraphAGUIAgent( """Build agents with auth context from frontend."""
user_roles = context.get("properties", {}).get("auth0_user_roles", [])
return [
LangGraphAgent(
name="vpi_1000", name="vpi_1000",
description="AI assistant with access to cave-related information through the Cavepedia MCP server", description="AI assistant with access to cave-related information through the Cavepedia MCP server",
graph=graph, graph=graph,
), langgraph_config={
path="/", "configurable": {
"context": {
"auth0_user_roles": user_roles,
}
}
},
) )
]
sdk = CopilotKitRemoteEndpoint(agents=build_agents)
add_fastapi_endpoint(app, sdk, "/copilotkit")
@app.get("/health") @app.get("/health")

2
web/agent/uv.lock generated
View File

@@ -1006,7 +1006,6 @@ name = "vpi-1000"
version = "1.0.0" version = "1.0.0"
source = { virtual = "." } source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "ag-ui-langgraph" },
{ name = "anthropic" }, { name = "anthropic" },
{ name = "copilotkit" }, { name = "copilotkit" },
{ name = "docstring-parser" }, { name = "docstring-parser" },
@@ -1023,7 +1022,6 @@ dependencies = [
[package.metadata] [package.metadata]
requires-dist = [ requires-dist = [
{ name = "ag-ui-langgraph", specifier = ">=0.0.4" },
{ name = "anthropic", specifier = ">=0.40.0" }, { name = "anthropic", specifier = ">=0.40.0" },
{ name = "copilotkit", specifier = ">=0.1.0" }, { name = "copilotkit", specifier = ">=0.1.0" },
{ name = "docstring-parser", specifier = ">=0.17.0" }, { name = "docstring-parser", specifier = ">=0.17.0" },

View File

@@ -2,7 +2,6 @@ import {
CopilotRuntime, CopilotRuntime,
ExperimentalEmptyAdapter, ExperimentalEmptyAdapter,
copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSAppRouterEndpoint,
LangGraphHttpAgent,
} from "@copilotkit/runtime"; } from "@copilotkit/runtime";
import { NextRequest } from "next/server"; import { NextRequest } from "next/server";
@@ -23,13 +22,17 @@ export const POST = async (req: NextRequest) => {
console.log("[copilotkit] session exists:", !!session); console.log("[copilotkit] session exists:", !!session);
console.log("[copilotkit] userRoles:", userRoles); console.log("[copilotkit] userRoles:", userRoles);
// 2. Create the CopilotRuntime instance with self-hosted agent // 2. Create the CopilotRuntime instance with remote endpoint
const runtime = new CopilotRuntime({ const runtime = new CopilotRuntime({
agents: { remoteEndpoints: [
"vpi_1000": new LangGraphHttpAgent({ {
url: process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8000", url: `${process.env.LANGGRAPH_DEPLOYMENT_URL || "http://localhost:8000"}/copilotkit`,
}), },
} ],
// Pass auth context as properties to the remote endpoint
properties: {
auth0_user_roles: userRoles,
},
}); });
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({ const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({