diff --git a/integrations/langgraph/python/ag_ui_langgraph/__init__.py b/integrations/langgraph/python/ag_ui_langgraph/__init__.py index 2b69e1a3f..ec7e0a453 100644 --- a/integrations/langgraph/python/ag_ui_langgraph/__init__.py +++ b/integrations/langgraph/python/ag_ui_langgraph/__init__.py @@ -12,9 +12,9 @@ LangGraphPlatformResultMessage, LangGraphPlatformActionExecutionMessage, LangGraphPlatformMessage, - PredictStateTool + PredictStateTool, ) -from .endpoint import add_langgraph_fastapi_endpoint +from .endpoint import add_langgraph_fastapi_endpoints __all__ = [ "LangGraphAgent", @@ -31,5 +31,5 @@ "LangGraphPlatformActionExecutionMessage", "LangGraphPlatformMessage", "PredictStateTool", - "add_langgraph_fastapi_endpoint" + "add_langgraph_fastapi_endpoints", ] diff --git a/integrations/langgraph/python/ag_ui_langgraph/endpoint.py b/integrations/langgraph/python/ag_ui_langgraph/endpoint.py index e2b5e355c..4086b62be 100644 --- a/integrations/langgraph/python/ag_ui_langgraph/endpoint.py +++ b/integrations/langgraph/python/ag_ui_langgraph/endpoint.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, HTTPException, Request +from fastapi import FastAPI, Request, APIRouter from fastapi.responses import StreamingResponse from ag_ui.core.types import RunAgentInput @@ -6,10 +6,15 @@ from .agent import LangGraphAgent -def add_langgraph_fastapi_endpoint(app: FastAPI, agent: LangGraphAgent, path: str = "/"): - """Adds an endpoint to the FastAPI app.""" - @app.post(path) +def add_langgraph_fastapi_endpoints( + app: FastAPI, agent: LangGraphAgent, path: str = "/" +): + """Adds endpoints to the FastAPI app.""" + + router = APIRouter(prefix=path.rstrip("/")) + + @router.post("/") async def langgraph_agent_endpoint(input_data: RunAgentInput, request: Request): # Get the accept header from the request accept_header = request.headers.get("accept") @@ -22,16 +27,17 @@ async def event_generator(): yield encoder.encode(event) return StreamingResponse( - event_generator(), - media_type=encoder.get_content_type() + event_generator(), media_type=encoder.get_content_type() ) - @app.get(f"{path}/health") + @router.get("/health") def health(): """Health check.""" return { "status": "ok", "agent": { "name": agent.name, - } - } \ No newline at end of file + }, + } + + app.include_router(router)