Gemini Interactions - Deep Research with File Search
Ground the Deep Research agent on your own documents.
The financial statements in the source are fictional demonstration data, not Agno financial information. The source checks only whether indexing is done and does not explicitly include web tools. Use the current adaptation to check errors and enable both document and public-web research.
"""
Gemini Interactions - Deep Research with File Search
=====================================================
Ground the Deep Research agent on your own documents.
This cookbook is self-contained: it creates a File Search store, uploads a
sample document, waits for indexing, then runs a Deep Research task that
searches that store alongside the public web.
Setup steps (done here in code so the example runs end to end):
1. client.file_search_stores.create(...) -> store with .name
2. client.file_search_stores.upload_to_file_search_store(store, file)
3. poll client.operations.get(op) until op.done
4. pass store.name to GeminiInteractions(file_search_store_names=[...])
In production you would create/populate the store once (offline) and only
reference it by name at query time.
"""
import tempfile
import time
from pathlib import Path
from agno.agent import Agent
from agno.models.google import GeminiInteractions
from google import genai
# ---------------------------------------------------------------------------
# 1-3. Create a File Search store and upload a document
# ---------------------------------------------------------------------------
client = genai.Client()
store = client.file_search_stores.create(
config={"display_name": "agno-deep-research-demo"}
)
print(f"Created store: {store.name}")
# A small sample document to ground the research on.
sample = Path(tempfile.gettempdir()) / "agno_fy2025_summary.txt"
sample.write_text(
"Agno FY2025 internal summary.\n"
"Revenue grew 240% year over year, driven by AgentOS adoption.\n"
"Headcount doubled. The flagship launch was the Antigravity integration.\n"
)
operation = client.file_search_stores.upload_to_file_search_store(
file_search_store_name=store.name,
file=str(sample),
config={"display_name": "fy2025-summary"},
)
print("Uploading + indexing document...")
while not operation.done:
time.sleep(3)
operation = client.operations.get(operation)
print("Document indexed.")
# ---------------------------------------------------------------------------
# 4. Run Deep Research grounded on the store
# ---------------------------------------------------------------------------
agent = Agent(
model=GeminiInteractions(
agent="deep-research-preview-04-2026",
thinking_summaries="auto",
file_search_store_names=[store.name],
),
markdown=True,
)
if __name__ == "__main__":
agent.print_response(
"Using our internal FY2025 summary, compare our reported growth drivers "
"against current public news about the AI agent framework market."
)Current adaptation
File Search stores persist until deleted, subject to embedding-model lifecycle limits. They are separate from the Files API's expiring uploads. These demo scripts create their own stores and use force=True to remove their documents during cleanup. Do not substitute a shared production store name. If cleanup fails, use the reported store name to delete the demo resource after resolving the error.
The operation's done state is not proof of successful indexing: inspect completed.error before querying. Citations depend on the generated answer; an empty citation field is possible.
The explicit tool list includes File Search, Google Search, and URL Context. These correspond to the requested private-document and web comparison; see Deep Research tools.
from pathlib import Path
from tempfile import TemporaryDirectory
from agno.agent import Agent
from agno.models.google import Gemini, GeminiInteractions
files_model = Gemini()
with TemporaryDirectory() as folder:
sample = Path(folder) / "fictional_summary.txt"
sample.write_text(
"Fictional ExampleCo test data: revenue grew 15 percent in FY2025. "
"Customers cited easier integration as the main reason for adoption.",
encoding="utf-8",
)
store = files_model.create_file_search_store(display_name="Fictional research demo")
try:
operation = files_model.upload_to_file_search_store(
file_path=sample, store_name=store.name
)
completed = files_model.wait_for_operation(operation, max_wait=300)
if completed.error:
raise RuntimeError(f"Indexing failed: {completed.error}")
agent = Agent(
model=GeminiInteractions(
agent="deep-research-preview-04-2026",
file_search_store_names=[store.name],
search=True,
url_context=True,
thinking_summaries="auto",
),
markdown=True,
)
agent.print_response(
"Compare the fictional ExampleCo growth drivers with current public news "
"about the AI agent framework market. Clearly label all fictional data."
)
finally:
files_model.delete_file_search_store(store.name, force=True)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno google-genaiExport your Google API key
export GOOGLE_API_KEY="your_google_api_key_here"Run the example
Save the current adaptation as deep_research_files_current.py, then run:
python deep_research_files_current.pyFull source: cookbook/90_models/google/gemini_interactions/deep_research_file_search.py