This is a starter template for building AI agents using Agent Spec and CopilotKit. It provides a modern Next.js application wired to a FastAPI backend that serves an Agent Spec agent (LangGraph runtime by default) with a sample weather tool.
- OpenAI-compatible API key (for the Agent Spec LLM)
- Python 3.10+
- uv
- Node.js 20+
- Any of the following package managers:
- pnpm (recommended)
- npm
- yarn
- bun
Note: This repository ignores lock files to avoid conflicts between different package managers. Each developer can generate a lock file locally with their preferred package manager.
Before installing, please clone the AG-UI repository into the same directory as this repo, with-agent-spec.
- Install dependencies using your preferred package manager:
# Using pnpm (recommended)
pnpm install
# Using npm
npm install
# Using yarn
yarn install
# Using bun
bun installNote: This automatically sets up the Python environment for the agent (via
postinstall). If you encounter issues, you can run:npm run install:agent
Note: this install both LangGraph and WayFlow runtimes for running your Agent Spec agents. The runtime can be selected when loading the agent in main.py, setting either langgraph or wayflow.
- (Optional) Set up your LLM environment variables:
Create a .env file inside the agent folder if you need to override defaults in the spec (agent/src/specs/agent.json):
OPENAI_API_KEY=sk-...your-api-key...
OPENAI_BASE_URL=https://api.your-provider.com/v1 # optional
OPENAI_MODEL=gpt-4o # optional
The backend loads this .env automatically (via python-dotenv). You can also set:
PORTto change the FastAPI server port (defaults to8000in this template)- Any provider-specific variables your tools require
- Start the development servers:
# Using pnpm
pnpm dev
# Using npm
npm run dev
# Using yarn
yarn dev
# Using bun
bun run devThis starts both the UI and the agent concurrently. The agent runs at http://localhost:8000/, and the UI runs at http://localhost:3000. The UI proxies requests to the agent (no extra env required by default).
To run only the UI or only the backend:
# Only UI
pnpm run dev:ui
# Only backend
pnpm run dev:agentYou can run these with any package manager:
dev- Starts both UI and agent servers in development modedev:debug- Starts development servers with debug logging enableddev:ui- Starts only the Next.js UI serverdev:agent- Starts only the Agent Spec FastAPI serverbuild- Builds the Next.js application for productionstart- Starts the production serverlint- Runs ESLint for code lintinginstall:agent- Installs Python dependencies for the agent
- UI entry points:
with-agent-spec/src/app/page.tsx,with-agent-spec/src/app/layout.tsx - Backend entry point:
with-agent-spec/agent/src/main.py - Agent Spec definition:
with-agent-spec/agent/src/specs/agent.json
- CopilotKit Documentation: https://docs.copilotkit.ai
- Next.js Documentation: https://nextjs.org/docs
Feel free to submit issues and enhancement requests! This starter is designed to be easily extensible.
This project is licensed under the MIT License - see the LICENSE file for details.
If you see "I'm having trouble connecting to my tools", make sure:
- The Agent Spec backend is running on port 8000
- The UI started successfully on port 3000
- If using a custom backend URL, set
NEXT_PUBLIC_COPILOTKIT_SERVER_URL
If you encounter Python import errors:
cd agent
uv sync
uv run src/main.py