This example contains a simple starter project which includes two different agents, one written in Python and one in JavaScript.
These instructions assume you are in the coagents-starter/ directory
-
Setup the Python agent:
cd agent-py poetry install echo "OPENAI_API_KEY=your_key_here" > .env
-
Run the agent:
langgraph dev --no-browser --port=8000 --config=langgraph.json --host=0.0.0.0
If you encounter a "No checkpointer set" error:
LANGGRAPH_API=true langgraph dev --no-browser --port=8000 --config=langgraph.json --host=0.0.0.0
-
Setup and run the UI (in a new terminal):
cd ui pnpm i echo "OPENAI_API_KEY=your_key_here" > .env pnpm run dev
-
Open http://localhost:3000 - The UI is already configured to connect to the Python agent running on port 8000.
First, install the backend dependencies:
cd agent-py
poetry installcd agent-js
pnpm installThen, create a .env file inside ./agent-py or ./agent-js with the following:
OPENAI_API_KEY=...
IMPORTANT: Make sure the OpenAI API Key you provide, supports gpt-4o.
You have two options for running the Python agent:
Option 1: Using LangGraph Dev Server (Recommended)
cd agent-py
LANGGRAPH_API=true langgraph dev --no-browser --port=8000 --config=langgraph.json --host=0.0.0.0Option 2: Using Poetry (Local FastAPI)
cd agent-py
poetry run demoThe agent code automatically detects which environment it's running in and handles checkpointer configuration accordingly.
First, install the dependencies:
cd ./ui
pnpm iThen start the client:
pnpm run devThen, create a .env file inside ./ui with the following:
OPENAI_API_KEY=...
The UI connects to your agent via the configuration in ui/app/api/copilotkit/route.ts. The current setup depends on which agent and method you're using:
If using LangGraph Dev Server (Option 1 - Recommended):
The current route.ts is already configured correctly:
langGraphPlatformEndpoint({
deploymentUrl: "http://localhost:8000", // matches langgraph dev port
langsmithApiKey: process.env.LANGSMITH_API_KEY || "",
agents: [{ name: "sample_agent", description: "A helpful LLM agent." }],
}),If using Poetry/FastAPI (Option 2):
Comment out the langGraphPlatformEndpoint and uncomment the basic endpoint:
// langGraphPlatformEndpoint({ ... }), // Comment this out
{
url: process.env.REMOTE_ACTION_URL || "http://localhost:8000/copilotkit",
},Change the deploymentUrl port and uncomment as shown:
langGraphPlatformEndpoint({
deploymentUrl: "http://localhost:8123", // JS agent runs on port 8123
langsmithApiKey: process.env.LANGSMITH_API_KEY || "",
agents: [{ name: 'sample_agent', description: 'A helpful LLM agent.' }]
}),Running the JS Agent:
- Run this command to start your LangGraph server
npx @langchain/langgraph-cli dev --host localhost --port 8123 - Run this command to connect your Copilot Cloud Tunnel to the LangGraph server
npx copilotkit@latest dev --port 8123
Navigate to http://localhost:3000.
Run LangGraph studio, then load the ./agent folder into it.
Make sure to create the .env mentioned above first!
A few things to try if you are running into trouble:
-
Port conflicts: Make sure there is no other local application server running on the 8000 port.
-
Network issues: Under
/agent-py/sample_agent/demo.py, change0.0.0.0to127.0.0.1or tolocalhost -
"No checkpointer set" error: This happens when the agent can't determine which environment it's running in. The agent code automatically detects this, but if you encounter this error:
- When using
langgraph dev: SetLANGGRAPH_API=truebefore running:LANGGRAPH_API=true langgraph dev ... - When using
poetry run demo: The agent should automatically use MemorySaver
- When using
-
Route configuration: Make sure your
ui/app/api/copilotkit/route.tsmatches your agent setup:- LangGraph dev server (port 8000) → Use
langGraphPlatformEndpoint - FastAPI demo (port 8000) → Use basic endpoint with
/copilotkitpath - JS agent (port 8123) → Use
langGraphPlatformEndpointwith port 8123
- LangGraph dev server (port 8000) → Use