Files
copilotkit__copilotkit/showcase/starters/langroid/agent_server.py
Jordan Ritter 59c073c610 fix: add agent_server.py to all Python starters, matching demo packages
Python starters were trying to run uvicorn with agent.<module>:app but
those modules don't export a FastAPI app. The demo packages use
agent_server.py as the FastAPI wrapper, so starters need it too.

Changes:
- Copy agent_server.py from each demo package into starter root,
  rewriting "from agents." to "from agent." for the starter layout
- Update all non-langgraph Python devScripts to use agent_server:app
- Update Dockerfile.python to COPY agent_server.py for non-langgraph
- Update getEntrypointBlock() generic Python to use agent_server:app
- Make langgraph-fastapi use langgraph_cli dev like langgraph-python
  (it was incorrectly configured as a uvicorn-based starter)
- Regenerate all starters
2026-04-14 15:41:34 -07:00

56 lines
1.1 KiB
Python
Generated

"""
Agent Server for Langroid
FastAPI server that hosts the Langroid agent backend.
The Next.js CopilotKit runtime proxies requests here via AG-UI protocol.
Langroid does not have a native AG-UI adapter, so we implement a custom
SSE endpoint that translates between Langroid's ChatAgent and the AG-UI
event stream.
"""
import os
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
from agent.agui_adapter import handle_run
load_dotenv()
app = FastAPI(title="Langroid Agent Server")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/")
async def run_agent(request: Request):
"""AG-UI /run endpoint — streams SSE events."""
return await handle_run(request)
@app.get("/health")
async def health():
return {"status": "ok"}
def main():
"""Run the uvicorn server."""
port = int(os.getenv("PORT", "8000"))
uvicorn.run(
"agent_server:app",
host="0.0.0.0",
port=port,
reload=True,
)
if __name__ == "__main__":
main()