Skip to content

lftraining/deepagent

Β 
Β 

Repository files navigation

Deep Agent Quickstart with Gemini 2.5 Flash

A comprehensive guide and working example for building deep agents using Google's Gemini 2.5 Flash model with the deepagents framework.

Overview

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.

Quick Start

1. Install Dependencies

pip install -r requirements.txt

Or with uv:

uv add -r requirements.txt

2. Set Up API Keys

Create a .env file from the template:

cp .env.example .env

Then add your API keys:

3. Run the Agent

python gemini_quickstart.py

Files in This Project

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

What Makes This Different From Anthropic?

Model Integration

# Anthropic (Claude)
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(model="claude-3-5-sonnet-20241022")

# Google (Gemini) - This project
from langchain_google_genai import ChatGoogleGenerativeAI
model = ChatGoogleGenerativeAI(model="gemini-2.5-flash")

Key Benefits of Gemini 2.5 Flash

  • ⚑ Speed: Optimized for fast inference
  • πŸ’° Cost: More economical pricing
  • πŸ“Š Context: 1 million token window
  • 🎯 Quality: Excellent performance-to-latency ratio

Agent Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      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    β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Example Usage

Basic Research Agent

from gemini_quickstart import agent

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "What are the latest developments in AI agents?"
    }]
})

print(result["messages"][-1].content)

Research with Specific Parameters

# Research with more search results
system_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,
)

Common Tasks

Change the Search Topic

Modify the internet_search call in your agent's instructions:

# For finance-specific research
topic = "finance"

# For current news
topic = "news"

# For general topics
topic = "general"

Add More Tools

Extend the agent with additional tools:

def calculator(expression: str) -> float:
    """Evaluate mathematical expressions"""
    return eval(expression)

agent = create_deep_agent(
    tools=[internet_search, calculator],
    system_prompt=research_instructions,
    model=model,
)

Create Specialized Subagents

Delegate specific tasks to specialized agents:

# Define system prompts for specialized agents
data_analyst_prompt = "You are an expert data analyst..."
summarizer_prompt = "You are an expert at summarizing content..."

# Agents will automatically handle delegation

Troubleshooting

Issue: "GOOGLE_API_KEY not found"

Solution: Make sure you've set the environment variable:

export GOOGLE_API_KEY="your-key-here"

Or use a .env file with python-dotenv:

from dotenv import load_dotenv
load_dotenv()

Issue: Rate limiting errors

Solution: Reduce request frequency or add delays:

import time
time.sleep(1)  # 1 second delay between searches

Issue: Large search results causing context issues

Solution: Use the built-in write_file tool to save results:

# Agent automatically manages this with FilesystemMiddleware
# No additional configuration needed

Performance Tips

  1. Use Flash model: It's faster and cheaper than Pro/Ultra models
  2. Limit search results: Set max_results=3-5 for focused searches
  3. Cache API keys: Set environment variables once, reuse across sessions
  4. Enable LangSmith: Monitor agent behavior and optimize
  5. Use file management: Let the agent offload context to files

Resources

License

This project is provided as an educational example.

Support

For issues with:

About

Deep Agent Examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%