A comprehensive guide and working example for building deep agents using Google's Gemini 2.5 Flash model with the deepagents framework.
This project demonstrates how to build intelligent research agents that can:
- Plan complex tasks using built-in planning tools
- Search the internet for information
- Manage file systems to handle large datasets
- Delegate subtasks to specialized subagents
- Synthesize research into polished reports
All powered by Google's fast and cost-efficient Gemini 2.5 Flash model.
pip install -r requirements.txtOr with uv:
uv add -r requirements.txtCreate a .env file from the template:
cp .env.example .envThen add your API keys:
- GOOGLE_API_KEY: Get from Google AI Studio
- TAVILY_API_KEY: Get from Tavily
python gemini_quickstart.py| File | Purpose |
|---|---|
GEMINI_QUICKSTART.md | Comprehensive guide to using Gemini with deep agents |
gemini_quickstart.py | Ready-to-run example script |
requirements.txt | Python dependencies |
.env.example | Template for environment variables |
README.md | This file |
# Anthropic (Claude)fromlangchain_anthropicimportChatAnthropicmodel=ChatAnthropic(model="claude-3-5-sonnet-20241022")
# Google (Gemini) - This projectfromlangchain_google_genaiimportChatGoogleGenerativeAImodel=ChatGoogleGenerativeAI(model="gemini-2.5-flash")- ⚡ Speed: Optimized for fast inference
- 💰 Cost: More economical pricing
- 📊 Context: 1 million token window
- 🎯 Quality: Excellent performance-to-latency ratio
┌─────────────────────────────────────────────┐
│ User Query (Research Task) │
└──────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Gemini 2.5 Flash Deep Agent │
│ ┌────────────────────────────────────────┐ │
│ │ System Prompt (Research Expert) │ │
│ └────────────────────────────────────────┘ │
└──────────────┬──────────────────────────────┘
│
┌──────┼──────┬──────────┬──────────┐
▼ ▼ ▼ ▼ ▼
┌─────┐ ┌──────┐ ┌────────┐ ┌──────┐ ┌─────┐
│Plan │ │Search│ │Organize│ │Write │ │Report│
│Work │ │Web │ │Files │ │File │ │Synth │
│Todos│ │ │ │ │ │ │ │ │
└─────┘ └──────┘ └────────┘ └──────┘ └─────┘
│ │ │ │ │
└──────┼────────┼─────────┼────────┘
│ │ │
▼ ▼ ▼
┌──────────────────────────────┐
│ Built-in Tools │
│ • write_todos │
│ • internet_search │
│ • read_file/write_file │
│ • grep/glob │
│ • execute │
│ • task (subagents) │
└──────────────────────────────┘
│
▼
┌──────────────────────────────┐
│ Final Report │
│ • Structured findings │
│ • Citations │
│ • Analysis & conclusions │
└──────────────────────────────┘
fromgemini_quickstartimportagentresult=agent.invoke({
"messages": [{
"role": "user",
"content": "What are the latest developments in AI agents?"
}]
})
print(result["messages"][-1].content)# Research with more search resultssystem_prompt="""You are an expert researcher...Use up to 10 search results per query for comprehensive coverage."""agent=create_deep_agent(
tools=[internet_search],
system_prompt=system_prompt,
model=model,
)Modify the internet_search call in your agent's instructions:
# For finance-specific researchtopic="finance"# For current newstopic="news"# For general topicstopic="general"Extend the agent with additional tools:
defcalculator(expression: str) ->float:
"""Evaluate mathematical expressions"""returneval(expression)
agent=create_deep_agent(
tools=[internet_search, calculator],
system_prompt=research_instructions,
model=model,
)Delegate specific tasks to specialized agents:
# Define system prompts for specialized agentsdata_analyst_prompt="You are an expert data analyst..."summarizer_prompt="You are an expert at summarizing content..."# Agents will automatically handle delegationSolution: Make sure you've set the environment variable:
export GOOGLE_API_KEY="your-key-here"Or use a .env file with python-dotenv:
fromdotenvimportload_dotenvload_dotenv()Solution: Reduce request frequency or add delays:
importtimetime.sleep(1) # 1 second delay between searchesSolution: Use the built-in write_file tool to save results:
# Agent automatically manages this with FilesystemMiddleware# No additional configuration needed- Use Flash model: It's faster and cheaper than Pro/Ultra models
- Limit search results: Set
max_results=3-5for focused searches - Cache API keys: Set environment variables once, reuse across sessions
- Enable LangSmith: Monitor agent behavior and optimize
- Use file management: Let the agent offload context to files
- Deepagents: https://github.com/langchain-ai/deepagents
- Google Gemini API: https://ai.google.dev
- Tavily Search: https://tavily.com
- LangChain: https://python.langchain.com
- LangGraph: https://langgraph.dev
This project is provided as an educational example.
For issues with:
- Deep agents: Check deepagents docs
- Gemini API: Visit Google AI Support
- Tavily: Contact Tavily Support