CopilotKit's BuiltInAgent in factory mode with TanStack AI as the LLM backend.
The agent runs in-process inside the Next.js API route — there is no separate agent server process to start (unlike the LangGraph TypeScript variant which spawns langgraph-cli on port 8123).
- Node.js 18+
- An OpenAI API key
- Clone & install dependencies
npm install- Set environment variables
Create a .env.local file from .env.example:
cp .env.example .env.localThen fill in your OPENAI_API_KEY:
OPENAI_API_KEY=sk-...
NEXT_PUBLIC_COPILOTKIT_AGENT=default
- Start the dev server
npm run devOpen http://localhost:3000 to see the demo index.
npm run build- Agent Factory: See
src/lib/factory/tanstack-factory.tsfor theBuiltInAgentwiring and TanStack AI integration. - Tools: Defined in:
src/lib/factory/state-tools.ts— state management toolssrc/lib/factory/server-tools.ts— server-side toolssrc/lib/factory/subagent-tools.ts— sub-agent tools
- API Route:
src/app/api/copilotkit/[[...slug]]/route.tshandles the AG-UI protocol.
Phase 3+ will add individual demo pages under src/app/demos/.