Skip to content

Commit a3ff477

Browse files
authored
feat: add /health endpoint to all starter integration examples (CopilotKit#3738)
## Summary Adds a `/health` GET endpoint returning `{"status": "ok"}` to all 11 starter integration examples. This is a best practice for any deployed service — health checks enable platform health monitoring, load balancer probes, and container lifecycle management. **11 starters updated:** - adk, agent-spec, agno, crewai-crews, crewai-flows, langgraph-fastapi, llamaindex, ms-agent-framework-dotnet, ms-agent-framework-python, pydantic-ai, strands-python **1 skipped:** - langgraph-python — uses `langgraph dev` which provides its own `/ok` endpoint All `/health` endpoints are registered before any catch-all mount to ensure they take priority (lesson learned from the pydantic-ai showcase bug). ## Test plan - [ ] Each starter builds successfully - [ ] `curl localhost:8000/health` returns `{"status": "ok"}` on each
2 parents 89e99c6 + 65508a6 commit a3ff477

11 files changed

Lines changed: 73 additions & 2 deletions

File tree

examples/integrations/adk/agent/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ def simple_after_model_modifier(
186186
# Add the ADK endpoint
187187
add_adk_fastapi_endpoint(app, adk_proverbs_agent, path="/")
188188

189+
190+
@app.get("/health")
191+
async def health():
192+
return {"status": "ok"}
193+
189194
if __name__ == "__main__":
190195
import os
191196

examples/integrations/agent-spec/agent/src/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def build_server() -> FastAPI:
1919
app = build_server()
2020

2121

22+
@app.get("/health")
23+
async def health():
24+
return {"status": "ok"}
25+
26+
2227
if __name__ == "__main__":
2328
uvicorn.run(
2429
"main:app",

examples/integrations/agno/agent/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@
1414
agent_os = AgentOS(agents=[agent], interfaces=[AGUI(agent=agent)])
1515
app = agent_os.get_app()
1616

17+
18+
@app.get("/health")
19+
async def health():
20+
return {"status": "ok"}
21+
22+
1723
if __name__ == "__main__":
1824
agent_os.serve(app="main:app", port=8000, reload=True)

examples/integrations/crewai-crews/agent/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
load_dotenv()
99

1010
app = FastAPI()
11+
12+
13+
@app.get("/health")
14+
async def health():
15+
return {"status": "ok"}
16+
17+
1118
add_crewai_crew_fastapi_endpoint(app, LatestAiDevelopment(), "/")
1219

1320
def main():

examples/integrations/crewai-flows/agent/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
load_dotenv()
1010

1111
app = FastAPI()
12+
13+
14+
@app.get("/health")
15+
async def health():
16+
return {"status": "ok"}
17+
18+
1219
add_crewai_flow_fastapi_endpoint(app, SampleAgentFlow(), "/")
1320

1421

examples/integrations/langgraph-fastapi/agent/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
_ = load_dotenv()
1111
app = FastAPI()
1212

13+
14+
@app.get("/health")
15+
async def health():
16+
return {"status": "ok"}
17+
18+
1319
add_langgraph_fastapi_endpoint(
1420
app=app,
1521
agent=LangGraphAGUIAgent(

examples/integrations/llamaindex/agent/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
from src.agent import agentic_chat_router
66

77
app = FastAPI()
8+
9+
10+
@app.get("/health")
11+
async def health():
12+
return {"status": "ok"}
13+
14+
815
app.include_router(agentic_chat_router)
916

1017

examples/integrations/ms-agent-framework-dotnet/agent/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
var loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
1919
var jsonOptions = app.Services.GetRequiredService<IOptions<JsonOptions>>();
2020
var agentFactory = new ProverbsAgentFactory(builder.Configuration, loggerFactory, jsonOptions.Value.SerializerOptions);
21+
22+
app.MapGet("/health", () => Results.Ok(new { status = "ok" }));
2123
app.MapAGUI("/", agentFactory.CreateProverbsAgent());
2224

2325
await app.RunAsync();

examples/integrations/ms-agent-framework-python/agent/src/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,19 @@ def _build_chat_client() -> ChatClientProtocol:
5555
allow_headers=["*"],
5656
)
5757

58+
5859
add_agent_framework_fastapi_endpoint(
5960
app=app,
6061
agent=my_agent,
6162
path="/",
6263
)
6364

6465

66+
@app.get("/health")
67+
async def health():
68+
return {"status": "ok"}
69+
70+
6571
if __name__ == "__main__":
6672
host = os.getenv("AGENT_HOST", "0.0.0.0")
6773
port = int(os.getenv("AGENT_PORT", "8000"))
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
from agent import ProverbsState, StateDeps, agent
2+
from starlette.applications import Starlette
3+
from starlette.responses import JSONResponse
4+
from starlette.routing import Mount, Route
25

3-
app = agent.to_ag_ui(deps=StateDeps(ProverbsState()))
6+
agui_app = agent.to_ag_ui(deps=StateDeps(ProverbsState()))
7+
8+
9+
async def health(request):
10+
return JSONResponse({"status": "ok"})
11+
12+
13+
app = Starlette(
14+
routes=[
15+
Route("/health", health),
16+
Mount("/", app=agui_app),
17+
]
18+
)
419

520
if __name__ == "__main__":
6-
# run the app
721
import uvicorn
822

923
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)

0 commit comments

Comments
 (0)