Chapter 20
AI Deep Research Agent
AI Deep Research Agent
A deep research assistant that plans, searches the web, writes to a virtual filesystem, and renders each tool call as a live card in a workspace pane. Built with CopilotKit, Deep Agents, AG-UI, and Tavily on top of Next.js + LangGraph (Python).
https://github.com/user-attachments/assets/68d5729f-91f9-4fd9-a579-cd1a8f4aad8d
Gen UI concept — tool-rendered components with a sidecar workspace. The Deep Agent emits four tools — write_todos, write_file, read_file, and research — and each one renders inline as a status card in the chat while updating a parallel workspace pane (plan, files, expandable tool results). Local React state mirrors the agent's filesystem via useDefaultTool rather than useCoAgent, sidestepping a Python Dict ↔ TypeScript Array type mismatch.
Prerequisites
- Node.js 18+
- Python 3.12+
- OpenAI API Key
- Tavily API Key
- uv (or pip) for Python deps
Getting Started
- Install Node dependencies:
npm install- Install Python dependencies for the agent:
cd agent
uv venv && source .venv/bin/activate
uv pip install -e .
cd ..Or with pip:
cd agent
python -m venv .venv && source .venv/bin/activate
pip install -e .
cd ..-
Copy
.env.exampleto.envin both the root andagent/directories, then fill inOPENAI_API_KEYandTAVILY_API_KEY. -
Start the agent (terminal 1):
cd agent
uv run python main.py- Start the frontend (terminal 2):
npm run devOpen http://localhost:3000 and ask the assistant to research any topic.
Architecture
[User asks research question]
↓
Next.js Frontend (CopilotChat + Workspace)
↓
CopilotKit Runtime → LangGraphHttpAgent
↓
Python Backend (FastAPI + AG-UI)
↓
Deep Agent (research_assistant)
├── write_todos (planning, built-in)
├── write_file (filesystem, built-in)
├── read_file (filesystem, built-in)
└── research(query)
└── internal Deep Agent [thread-isolated]
└── internet_search (Tavily)Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
OPENAI_API_KEY | Yes | - | Get API key |
TAVILY_API_KEY | Yes | - | Get API key |
OPENAI_MODEL | No | gpt-5.5 | Model to use (gpt-5.5) |
LANGGRAPH_DEPLOYMENT_URL | No | http://localhost:8123 | Backend URL |
SERVER_HOST | No | 0.0.0.0 | Backend host |
SERVER_PORT | No | 8123 | Backend port |
Learn more
- Deep Agents documentation
- Building Frontends for Deep Agents
- CopilotKit documentation
- Tavily documentation
License
Upstream license applies — see CopilotKit/CopilotKit.
