Skip to main content

Python SDK for deep research using Gemini with search grounding

Project description

deep-research-sdk

A Python SDK for conducting deep research using Google's Gemini models with built-in search grounding. No external search APIs required.

Installation

pip install deep-researcher-sdk

Or with uv:

uv add deep-researcher-sdk

Quick Start

from deep_research import research

result = research("What are the top trends in B2B SaaS marketing in 2025?")
print(result.report)

Configuration

Set your Gemini API key as an environment variable:

export GEMINI_API_KEY="your-api-key"

Get a free API key from Google AI Studio.

Usage

Simple Usage

from deep_research import research

result = research("Your research query here")

# Access the results
print(result.plan)       # Research plan
print(result.learnings)  # List of learnings from searches
print(result.report)     # Final synthesized report

Save Output to Files

from deep_research import research

result = research(
    "Your research query here",
    output_dir="./research_output"
)
# Saves: plan.md, learning_1.md, ..., learnings.md, report.md

Custom Models

from deep_research import research

result = research(
    "Your research query here",
    thinking_model="gemini-2.5-pro",  # For planning and synthesis
    task_model="gemini-2.5-flash",     # For search tasks
)

Class-Based Usage

from deep_research import DeepResearcher

researcher = DeepResearcher(
    thinking_model="gemini-2.5-pro",
    task_model="gemini-2.5-flash",
    api_key="your-api-key",  # Optional, defaults to GEMINI_API_KEY env var
)

# Run full research
result = researcher.research("Your query", output_dir="./output")

# Or run individual steps
plan = researcher.write_plan("Your query")
queries = researcher.generate_search_queries(plan)
learnings = [researcher.search_and_learn(q.query, q.research_goal) for q in queries]
report = researcher.write_report(plan, learnings)

How It Works

The SDK orchestrates a multi-step research flow:

  1. Plan Generation - Uses the thinking model to create a structured research plan
  2. Query Generation - Generates 3-5 targeted search queries based on the plan
  3. Search & Learn - Executes each query using Gemini's built-in search grounding, extracting key learnings
  4. Report Synthesis - Combines all learnings into a comprehensive final report

Dual Model Architecture

The SDK uses two models optimized for different tasks:

  • Thinking Model (gemini-2.5-pro): Used for planning, query generation, and final report synthesis. Optimized for reasoning and complex synthesis.
  • Task Model (gemini-2.5-flash): Used for search tasks with grounding enabled. Optimized for speed and web search integration.

Output Structure

When using output_dir, the SDK saves:

output_dir/
├── plan.md           # Research plan
├── learning_1.md     # First search result
├── learning_2.md     # Second search result
├── ...
├── learnings.md      # All learnings combined
└── report.md         # Final synthesized report

Adding to Letta Agents

1. Add dependency to your Letta Dockerfile

FROM letta/letta:latest

RUN /app/.venv/bin/python3 -m pip install deep-researcher-sdk

Make sure GEMINI_API_KEY is set in your Letta environment.

2. Create a tool file (e.g., deep_research_tool.py)

def deep_research(query: str) -> str:
    """
    Conduct deep research on a topic and return a comprehensive report.

    Use this tool when you need to research a topic thoroughly before
    making recommendations or answering complex questions. The query
    should be specific and well-defined.

    Args:
        query (str): The research topic or question to investigate

    Returns:
        str: A comprehensive markdown report with findings and sources
    """
    from deep_research import research
    result = research(query)
    return result.report

3. Register and attach to your agent

from letta_client import Letta

client = Letta(base_url="http://localhost:8283")

# Create tool from file
tool = client.tools.create_from_file(filepath="deep_research_tool.py")

# Attach to agent
client.tools.attach_to_agent(agent_id="your-agent-id", tool_id=tool.id)

Requirements

  • Python 3.12+
  • Google Gemini API key

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deep_researcher_sdk-0.1.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deep_researcher_sdk-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file deep_researcher_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: deep_researcher_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for deep_researcher_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63bcc6c65336c621b985f7108d812b622d032e9af4c4b354ac796fbbab244be8
MD5 b9c15446d477581863f03af27dbf31b5
BLAKE2b-256 208edbfc50ea096f37817f5bde3f534ae272a0987236acbadcede027cdae1acd

See more details on using hashes here.

File details

Details for the file deep_researcher_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for deep_researcher_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad992b540a9dc78f0de792821b09d1e015f7e7ebe4bb5a03d0881d28fb123de8
MD5 ca1e2f1fb1482527521eecdf88ca193f
BLAKE2b-256 1d508590fa1dcdaa158f387089a78aebfccd664e4f1f0cd6f3784fef728827a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page