Skip to main content
Lesson 6 of 18 · Mistral Agents: Building Autonomous AI

Agent with Web Search

Lesson 6 of 18 Updated November 2, 2026 Developer
On this page
  1. Give Your Agent Access to the Web
  2. Create an Agent with Web Search
  3. Use the Agent
  4. Understand the Response Structure
  5. What Search Makes Possible
  6. web_search vs. web_search_premium
  7. Key Takeaways

Give Your Agent Access to the Web

An LLM without internet access is limited to its training data. Ask it about a regulatory text passed last month, and it will either claim ignorance or—worse—respond based on its memorized state of the world without flagging that the information is outdated. By enabling the web_search tool on your agent, you let it find real-time information and cite its sources, improving both the freshness and verifiability of its answers.

Activation takes just one line of configuration, but instructions determine the quality of the output. The example below enforces strict discipline: search systematically, cite URLs, date the findings, and flag contradictions between sources.

from mistralai.client import Mistral
import os

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

agent = client.beta.agents.create(
    model="mistral-medium-latest",
    name="News Agent",
    instructions="""You are a news analyst.
- Use web search for every question
- Always cite your sources with URLs
- Specify the date of the information found
- If results are contradictory, mention it""",
    tools=[{"type": "web_search"}],
    completion_args={"temperature": 0.3, "top_p": 0.95}
)

The last instruction is the most valuable in practice. Without it, a model faced with two diverging figures might pick one and present its synthesis as an established fact. A low temperature complements this setup by reducing hallucination when reformulating results.

The web_search tool provides access to a standard search engine. For verified news sources, use web_search_premium:

tools=[{"type": "web_search_premium"}]

Use the Agent

The call is no different from that of an agent without tools: you do not trigger the search; the agent decides when it is necessary.

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="What are the latest developments in AI regulation in Europe?"
)

Understand the Response Structure

The change is most apparent when reading the response. An agent with web search returns several types of entries. Code that simply reads the first entry would display search metadata instead of the expected text.

for entry in response.outputs:
    if entry.type == "tool.execution":
        # Web search metadata
        print(f"Tool used: {entry.tool_name}")
        print(f"Search query: {entry.info}")

    elif entry.type == "message.output":
        # Agent response with citations
        for chunk in entry.content:
            if chunk.type == "text":
                print(chunk.text)
            elif chunk.type == "tool_reference":
                print(f"  Source: {chunk.title} — {chunk.url}")

Note the nested loop: the content of a message.output is not a single string but a sequence of chunks, alternating text fragments and references. Each section of the response can thus include tool_reference objects containing three fields:

  • tool — Name of the source tool (web_search)
  • title — Title of the cited web page
  • url — Reference URL

This is a major advantage: your agent does not just answer; it proves its claims with verifiable sources. In an interface, these fields become clickable links placed at the right spot in the text, allowing users to trace every claim back to its origin.

What Search Makes Possible

Start with monitoring. An agent whose instructions frame the output format turns an open-ended question into a regular, comparable weekly synthesis.

agent = client.beta.agents.create(
    model="mistral-large-latest",
    name="Tech Watch",
    instructions="Conduct technology monitoring. Summarize the 5 most important news items on the requested topic.",
    tools=[{"type": "web_search"}]
)

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="Monitoring on AI agents — last 2 weeks"
)

Fact-checking comes next, with instructions taking the form of an explicit procedure. The agent does not need to decide on a method; the method is dictated, making the output predictable.

agent = client.beta.agents.create(
    model="mistral-large-latest",
    name="Fact Checker",
    instructions="""Verify the following claims.
For each claim:
1. Search for reliable sources
2. Indicate if it is true, false, or partially true
3. Cite your sources""",
    tools=[{"type": "web_search"}]
)

Comparison closes the series: here, the question itself carries the decision criteria. The more you specify the actual constraints—technology, volume—the more targeted the triggered searches will be.

response = client.beta.conversations.start(
    agent_id=agent.id,
    inputs="Compare cloud offerings from OVH, Scaleway, and AWS for hosting a Python application with 10K users/day."
)

web_search vs. web_search_premium

Aspectweb_searchweb_search_premium
EngineStandard searchAdvanced search
SourcesGeneral webVerified news providers
CostIncludedExtra cost
UsageGeneral informationReliable news

For most use cases, web_search is sufficient. Reserve web_search_premium for applications where source reliability is critical (journalism, compliance, regulatory monitoring). The reasoning should not be “which option is best” but “what is the cost of a dubious source in my context”: for an internal news summary, it is zero; for a note submitted to a regulator, it is not.

Key Takeaways

  • The web_search tool lets the agent search the internet in real time
  • Responses include citations with the source title and URL
  • web_search_premium offers verified news sources for an additional cost
  • Low temperature (0.3) is recommended for factual tasks involving search
  • The agent automatically decides when and how to use web search