showcase/shell-docs/src/content/docs/integrations/agent-spec/langgraph.mdx
Wire an Agent Spec agent backed by LangGraph to CopilotKit’s UI via the AG‑UI event protocol. You’ll run a FastAPI endpoint that emits AG‑UI events and point your Next.js app at it.
Key pieces:
ag-ui/integrations/agent-spec/python/ag_ui_agentspec/endpoint.pyag-ui/integrations/agent-spec/python/examples/server.pynpx copilotkit@latest createUse this integration when you already have a LangGraph-based agent described by an Agent Spec and want a turnkey UI that streams assistant text, tool calls/results, and run lifecycle with minimal wiring.
pyagentspec)From the AG‑UI repo’s Agent Spec integration package:
git clone https://github.com/ag-ui-protocol/ag-ui.git
cd ag-ui/integrations/agent-spec/python
uv pip install -e .[langgraph]
Note that this installs pyagentspec from source. Alternatively, you may install it with pip:
pip install pyagentspec[langgraph]
Use the LangGraph runtime to execute your Agent Spec and stream AG‑UI events.
from fastapi import FastAPI
from ag_ui_agentspec.agent import AgentSpecAgent
from ag_ui_agentspec.endpoint import add_agentspec_fastapi_endpoint
agentspec_json = <loaded json/yaml string of your Agent Spec config>
app = FastAPI()
agent = AgentSpecAgent(agentspec_json, runtime="langgraph")
add_agentspec_fastapi_endpoint(app, agentspec_agent=agent, path="/")
Run locally:
uvicorn backend.app:app --reload --port 8000
If you already have the starter, make sure your agent runs on port 8000.
Then run the app (for example with pnpm dev) and open http://localhost:3000.
AgentSpecAgent(runtime="langgraph") executes your Agent Spec agent with the LangGraph framework.AgentSpecAgent wrapper, AgUiSpanProcessor maps Agent Spec tracing spans to AG‑UI events on a per‑request queue (EVENT_QUEUE).TEXT_MESSAGE_START/CONTENT/ENDTOOL_CALL_START/ARGS/END and TOOL_CALL_RESULTRUN_STARTED/RUN_FINISHEDStarter template: https://github.com/CopilotKit/CopilotKit/tree/main/examples/integrations/agent-spec (see the README for installation options)