A research agent plans, searches, reads, revises, and cites where each claim came from, instead of answering from training data alone. This cookbook wires Tavily web search into a Deep Agent driven by a Nebius Token Factory model, so the answer is grounded in pages fetched at runtime.
What you will build
A research agent that takes a question, decomposes it into sub-questions, runs advanced Tavily searches, and returns a structured report. It has three pieces:
- MiniMax-M3 on Nebius Token Factory as the reasoning model, reached through
langchain-nebius. - Tavily Search as the agent’s tool, configured for advanced depth and five results per query.
deepagentsto supply the planning loop, the virtual file system for notes, and the sub-agents that turn a chat model into a researcher.
A measured run of the default question made 6 model requests, cost about $0.07 at Token Factory pricing, and produced a 20,000-character report in under 90 seconds.
Prerequisites
- Python 3.12 or newer
- A Nebius Token Factory account with access to
MiniMaxAI/MiniMax-M3 - A Tavily account and API key
- Both credentials in environment variables, never in a notebook cell or a commit
Run the cookbook
-
Install the dependencies:
python -m venv .venv && source .venv/bin/activate pip install -U deepagents langchain langchain-core langchain-nebius langchain-tavily tavily-python -
Export both credentials:
export NEBIUS_API_KEY="your-token-factory-key" export TAVILY_API_KEY="your-tavily-key" -
Build the agent from a search tool, a model, and one call that combines them:
from deepagents import create_deep_agent from langchain_nebius import ChatNebius from langchain_tavily import TavilySearch tavily_search = TavilySearch(max_results=5, search_depth="advanced") model = ChatNebius(model="MiniMaxAI/MiniMax-M3") agent = create_deep_agent(model=model, tools=[tavily_search]) -
Ask a research question and print the report:
result = agent.invoke({ "messages": [ { "role": "user", "content": "Research GPUs available in the US in 2026 and write a detailed report.", } ] }) print(result["messages"][-1].content)
Everything between the question and the report is the agent deciding what to search for, what to read, and when it has enough to write.
Verify the result
A successful run returns a report with concrete, checkable specifics (named products, dates, figures) and the sources Tavily surfaced. If the output reads like a generic summary with no sources, the search tool was never invoked; check that TAVILY_API_KEY is set in the same environment.
To see the agent’s planning steps and tool calls rather than just the answer, print the whole state instead of the last message:
import json
print(json.dumps(result, indent=2, default=str))
Troubleshooting
- 401 from Token Factory: the key is missing, expired, or scoped to a different project. Re-export
NEBIUS_API_KEYand retry. - Empty or missing search results: confirm the Tavily key is active and your plan has remaining credits.
- The run takes a minute or two: this is expected. A research pass makes several model calls, and advanced search depth is slower than basic.
Clean up
The cookbook creates no cloud resources, so there is nothing to tear down:
deactivate && rm -rf .venv
unset NEBIUS_API_KEY TAVILY_API_KEY
If you ever pasted either key into a notebook, a shell history file, or a commit, rotate it in the Token Factory console and the Tavily dashboard rather than deleting the file and assuming it is gone.