Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions integrations/langgraph/python/ag_ui_langgraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -31,5 +31,5 @@
"LangGraphPlatformActionExecutionMessage",
"LangGraphPlatformMessage",
"PredictStateTool",
"add_langgraph_fastapi_endpoint"
"add_langgraph_fastapi_endpoints",
]
24 changes: 15 additions & 9 deletions integrations/langgraph/python/ag_ui_langgraph/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from fastapi import FastAPI, HTTPException, Request
from fastapi import FastAPI, Request, APIRouter
from fastapi.responses import StreamingResponse

from ag_ui.core.types import RunAgentInput
from ag_ui.encoder import EventEncoder

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")
Expand All @@ -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,
}
}
},
}

app.include_router(router)