49ba63214068e785f7adce75cf4e942a014a8faa
Deep Agent with StateGraph
This repository contains a minimal implementation of a Deep Agent based on the
deep-agents-from-scratch notebook. The agent uses a LangGraph
StateGraph to orchestrate the following steps:
- Think – decide what to search for.
- Search – perform a web search with Tavily.
- Summarize – summarize each search result and store the raw content in a virtual file system.
- Write File – dump all virtual files to disk.
The implementation follows the modern LangChain API guidelines:
- All imports use the current modular packages (
langchain_openai,langgraph,langchain_core, etc.). - No legacy
langchain.chat_modelsorlangchain.llmsimports. - The agent can be run from the command line.
Setup
# Create a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the agent interactively
python src/deep_agents_from_scratch/deep_agent.py
Usage
After starting the script you will be prompted to enter a research question.
The agent will perform a web search, summarize the results, and write the
raw content to the output/ directory.
Project Structure
src/
├── deep_agents_from_scratch/
│ ├── __init__.py
│ ├── deep_agent.py
│ ├── research_tools.py
│ └── state.py
state.py– defines theDeepAgentStatedataclass used by the graph.research_tools.py– contains the Tavily search, think, and summarization tools.deep_agent.py– builds theStateGraph, defines node functions, and provides a CLI entry point.
Extending the Agent
You can add more tools or nodes by following the pattern used in
deep_agent.py. For example, to add a node that writes the summaries to a
PDF you would:
- Create a new tool that formats the summaries.
- Add a node function that calls the tool.
- Connect the node in the graph.
License
MIT License.
Languages
Python
100%