How to use Deep Research with the Gemini API
The Gemini Deep Research Agent autonomously plans, searches, and synthesizes long-horizon research tasks into detailed, cited reports.
Deep Research handles long-running tasks by executing in the background. It is exclusively available through the Interactions API (not generate_content).
Two new versions are available:
deep-research-preview-04-2026: Designed for speed & efficiency, ideal to be streamed back to a client UIdeep-research-max-preview-04-2026: Maximum comprehensiveness for automated context gathering & synthesis
What's new#
- Collaborative planning: Review and refine the research plan before execution
- Native charts & infographics: Agent-generated charts, graphs, and infographics
- Remote MCP server: Connect external tools via the Model Context Protocol
- Extended tooling: Google Search, URL Context, Code Execution, MCP, and File Search
- Multimodal research grounding: Pass images, PDFs, and audio as research context
Setup#
Install the Python SDK:
Shell
Set your API key as an environment variable. You can create one at aistudio.google.com/apikey.
Shell
Run your first Deep Research task#
Start a research task with background=True and poll for the result. Deep Research is asynchronous as tasks can take several minutes to complete.
Python
=
=
=
break
== :
break
Collaborative planning#
Set collaborative_planning=True to get a research plan back instead of running immediately. Iterate on the plan with previous_interaction_id, then set collaborative_planning=False to execute.
Step 1: Request a plan
Python
=
=
Refine the plan: Use previous_interaction_id to continue the conversation. Keep collaborative_planning=True to stay in planning mode. Repeat as needed.
Python
=
Approve and execute: Set collaborative_planning=False to approve the plan and start the research.
Important: You must explicitly set collaborative_planning=False on the final turn. Simply sending "go ahead" without flipping the flag will not trigger report generation.
Python
=
Native charts and infographics#
Set visualization="auto" and ask for visuals in your prompt. The agent generates charts and infographics returned as base64-encoded images.
Python
=
=
== and :
=
# display(Image(data=image_bytes)) # Jupyter
Tip: Setting visualization="auto" enables the capability, but best results are achieved by explicitly asking for what you want.
Remote MCP servers#
Connect remote MCP servers to give the agent access to external tools. Pass the server name, url, and optional auth headers.
Python
=
MCP servers support no-auth, bearer token, and OAuth. For OAuth, fetch the token with a library like google-auth and pass it in headers. Use allowed_tools to restrict which tools the agent can call from the server.
Tool configuration#
By default the agent uses Google Search, URL Context, and Code Execution. You can customize the tools the agent can use by providing a list of tools, similar to models. This allows you to, for example, only search the web (via google_search and url_context), only search private sources (via file_search and custom MCP servers), or search a mix of both.
| Tool | Type | Default | Description |
|---|---|---|---|
| Google Search | google_search |
✅ | Search the public web |
| URL Context | url_context |
✅ | Read and summarize web pages |
| Code Execution | code_execution |
✅ | Run code for calculations and data analysis |
| MCP Server | mcp_server |
— | Connect remote MCP servers |
| File Search | file_search |
— | Search uploaded document corpora |
Python
# Only web search allowed
=
Note: Passing no tools at all defaults to Search, URL Context, and Code Execution enabled.
Multimodal research grounding#
Pass images, PDFs, and documents alongside your text prompt to ground the research.
Python
=
Real-time streaming with visuals and thought summaries#
Stream research progress in real time. Enable thinking_summaries="auto" to receive the agent's intermediate reasoning alongside text and generated images.
Python
=
= None
= None
= False
global , ,
=
=
== :
== and :
=
in :
= True
=
# Reconnect if the connection drops
=
break
=