Skip to content

Built-in Provider Tools#

AG2 includes built-in tools that map to capabilities offered by LLM providers. Almost all of them are executed by the provider's API — not locally — and require no function implementation on your side. The one exception is marked in the table below.

Tool Anthropic OpenAI Gemini xAI Z.AI
CodeExecutionTool ✓ ✓ ✓ ✓ ✗
WebSearchTool ✓ ✓ ✓ ✓ ✓
WebFetchTool ✓ ✗ ✓ ✗ ✗
FileSearchTool ✗ ✓ ✓ ✗ ✗
ShellTool ✗ ✓ ✗ ✗ ✗
AnthropicBashTool ✓ ✗ ✗ ✗ ✗
SkillsTool ✓ ✓ ✗ ✗ ✗
MCPServerTool ✓ ✓ ✗ ✓ ✗
ImageGenerationTool ✗ ✓ ✗ ✗ ✗
MemoryTool ✓ ✗ ✗ ✗ ✗
XSearchTool ✗ ✗ ✗ ✓ ✗
RetrievalTool ✗ ✗ ✗ ✗ ✓
GoogleMapsTool ✗ ✗ ✓ ✗ ✗

Note

AnthropicBashTool is the exception: Anthropic ships the tool definition but does not run it, so AG2 executes the command on your machine and sends the output back. See Anthropic Bash.

Gives the model access to real-time web search results.

from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import WebSearchTool, UserLocation

agent = Agent(
    "researcher",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[
        WebSearchTool(
            max_uses=5,
            user_location=UserLocation(country="US"),
            allowed_domains=["github.com", "pypi.org"],
            blocked_domains=["pinterest.com"],
        ),
    ],
)

Not all parameters are supported by every provider. Unsupported parameters are silently ignored.

Parameter Anthropic OpenAI Gemini xAI Z.AI
max_uses ✓ ✓ ✗ ✗ ✗
user_location ✓ ✓ ✗ ✓ ✗
search_context_size ✗ ✓ ✗ ✗ ✓
allowed_domains ✓ ✓ ✗ ✓ ✗
blocked_domains ✓ ✗ ✓ ✓ ✗

Note

Z.AI maps WebSearchTool to its search-prime engine and only honors search_context_size (as content_size); the other parameters are silently ignored.

Web Fetch#

Fetches full content from specific URLs. Useful for reading documentation, articles, or PDFs.

from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import WebFetchTool

agent = Agent(
    "researcher",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[
        WebFetchTool(
            max_uses=3,
            max_content_tokens=50000,
            citations=True,
        ),
    ],
)
Parameter Anthropic Gemini
max_uses ✓ ✗
allowed_domains ✓ ✗
blocked_domains ✓ ✗
citations ✓ ✗
max_content_tokens ✓ ✗
strict ✓ ✗
use_cache ✓ (from web_fetch_20260309) ✗
response_inclusion ✓ (web_fetch_20260318 only) ✗
url_sources ✓ ✗

Two of those options arrived with later tool versions. Setting one on a version that predates it raises WebFetchOptionUnsupportedError while the request is built, naming the option and the version it arrived in. The API refuses the same pairing with a 400, so this costs you the round trip and tells you which version to ask for:

from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import WebFetchTool

agent = Agent(
    "researcher",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[
        # Asking this agent anything raises: `use_cache` needs web_fetch_20260309 or later,
        # and no request is sent.
        WebFetchTool(use_cache=False, version="web_fetch_20250910"),
    ],
)

Which sources may supply a URL#

url_sources says, per source, which URLs the model is allowed to fetch. It is a policy control rather than a tuning knob: an agent that fetches URLs out of user text is reachable by anyone who can type into the conversation, and allowed_domains cannot stand in for it because that filters by host, not by who proposed the URL.

from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import tool
from ag2.tools.builtin.web_fetch import OnlyTools, UrlSources, WebFetchTool

@tool
async def search_docs(query: str) -> list[str]:
    """Return the URLs of documents matching the query."""
    return ["https://docs.example.com/guide"]

agent = Agent(
    "researcher",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[
        search_docs,
        WebFetchTool(
            # Fetch only what `search_docs` returned — never a link a user pasted.
            url_sources=UrlSources(
                user_input="none",
                client_tool_results=OnlyTools(["search_docs"]),
            ),
        ),
    ],
)

user_input is "all" or "none". client_tool_results and server_tool_results take those two as well as OnlyTools([...]) and ExceptTools([...]), which name tools. A name must belong to a tool the same request declares; one that does not raises WebFetchUrlSourceToolNotFoundError before the request is sent, because the API resolves those names against tools[] and a policy naming a tool that is not there covers nothing.

A source you leave unset is not sent, and the API's default applies to it. Measured 2026-09-19, that default is permissive: with url_sources omitted, a URL reaching the model only through a user message is fetched, and so is one reaching it only through a client tool's result.

Note

OpenAI does not support web fetch. Using WebFetchTool with an OpenAI config will raise an error.

Note

Gemini maps WebFetchTool to url_context and honors none of these options. It ignores them rather than refusing them, including the version-gated ones.

Google Maps#

GoogleMapsTool enables Grounding with Google Maps on the Gemini 3 family, giving the model access to up-to-date places, business info, and location data.

from ag2 import Agent
from ag2.config import GeminiConfig
from ag2.tools import GoogleMapsTool

agent = Agent(
    "concierge",
    config=GeminiConfig(model="gemini-3-flash-preview"),
    tools=[
        GoogleMapsTool(
            latitude=40.7128,
            longitude=-74.0060,
            language_code="en",
        ),
    ],
)
Parameter Description
latitude / longitude Bias results toward a location (sent via tool_config.retrieval_config). Both required for geo-biasing.
language_code Localise results (e.g. "en").
enable_widget Request the interactive Maps widget context token.

Note

GoogleMapsTool is only supported by Gemini. All other providers raise UnsupportedToolError.

FileSearchTool lets the model search a provider-hosted document store and ground its answers in the retrieved chunks. On OpenAI this searches vector stores (upload files via the OpenAI SDK or dashboard, then reference the store by id); on Gemini this searches FileSearchStore resources.

from ag2 import Agent
from ag2.config import OpenAIResponsesConfig
from ag2.tools import FileSearchTool

agent = Agent(
    "librarian",
    config=OpenAIResponsesConfig(model="gpt-4o"),
    tools=[
        FileSearchTool(
            vector_store_ids=["vs_abc123"],
            max_num_results=4,
            include_results=True,
        ),
    ],
)
Parameter Description
vector_store_ids OpenAI only. Required for OpenAI. Ids of the vector stores to search.
max_num_results Cap the number of retrieved chunks. Maps to Gemini's top_k.
filters OpenAI only. An OpenAI comparison or compound filter object, passed through verbatim.
include_results Return the raw retrieved chunks in the tool result (adds include=["file_search_call.results"]). Off by default — chunks are full text and inflate responses.
store_names Gemini only. Required for Gemini. Gemini FileSearchStore resource names to search.
metadata_filter Gemini only. AIP-160 filter string applied to store metadata.

vector_store_ids and filters are OpenAI-only; store_names and metadata_filter are Gemini-only. max_num_results is shared and maps to Gemini's top_k.

Search activity surfaces on the event stream as BuiltinToolCallEvent / BuiltinToolResultEvent pairs. With include_results=True the result event carries each chunk as a TextInput part, plus per-file relevance scores in metadata["results"].

Note

FileSearchTool is supported by the OpenAI Responses API (OpenAIResponsesConfig) and Gemini (GeminiConfig). Other providers raise an error.

Code Execution#

Lets the model write and run code inline during a conversation.

1
2
3
4
5
6
7
8
9
from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import CodeExecutionTool

agent = Agent(
    "analyst",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[CodeExecutionTool()],
)

The tool accepts a version parameter for provider version pinning:

CodeExecutionTool(version="code_execution_20260521")

Accepted versions: code_execution_20250825 (default), code_execution_20260120, and code_execution_20260521.

Memory#

Enables Claude to store and retrieve information across conversations. Claude can create, read, update, and delete files in a /memories directory.

1
2
3
4
5
6
7
8
9
from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import MemoryTool

agent = Agent(
    "assistant",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[MemoryTool()],
)

Note

MemoryTool is currently only supported by Anthropic.

Shell#

Gives the model the ability to run shell commands inside a provider-hosted environment. Only OpenAI offers one; the environment carries the backend configuration.

from ag2 import Agent
from ag2.config import OpenAIResponsesConfig
from ag2.tools import ShellTool
from ag2.tools.builtin.shell import ContainerAutoEnvironment, NetworkPolicy

agent = Agent(
    "devops",
    config=OpenAIResponsesConfig(model="gpt-4.1"),
    tools=[
        ShellTool(
            environment=ContainerAutoEnvironment(
                network_policy=NetworkPolicy(allowed_domains=["pypi.org"]),
            ),
        ),
    ],
)
Environment Description
ContainerAutoEnvironment Provider-managed container with optional network policy
ContainerReferenceEnvironment Reference an existing container by ID

On OpenAI, name an environment

ShellTool() without an environment is a client-executed shell: OpenAI returns a shell_call for your application to run, and AG2 has no path to execute it and feed the output back — so the turn would end with no result and no reply. AG2 refuses it with ClientExecutedShellUnsupportedError rather than let it happen silently. Pass ContainerAutoEnvironment() for the hosted shell, or use SandboxShellTool, which AG2 executes itself and works with any provider.

Warning

ShellTool gives the model direct shell access. Use it only with trusted prompts and consider restricting the environment.

Not available on Anthropic

Anthropic's own shell tool is client-executed — it defines the tool but runs nothing, so a provider-hosted shell has no meaning there and ShellTool raises UnsupportedToolError. Use AnthropicBashTool for Anthropic's tool, or SandboxShellTool for a provider-neutral shell.

Anthropic Bash#

AnthropicBashTool declares Anthropic's bash_20250124 tool. Anthropic does not execute it: the model returns an ordinary tool_use block and waits for a tool_result, so AG2 runs the command for you and sends the output back.

from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import AnthropicBashTool

agent = Agent(
    "devops",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[AnthropicBashTool()],
)

reply = await agent.ask("How many Python files are in this directory?")
print(await reply.content())

With no arguments, commands run in a local subprocess. Execution is backed by the same machinery as SandboxShellTool, so the first argument picks the backend and the keyword arguments restrict what the model may run:

1
2
3
4
5
6
7
8
from ag2.extensions.docker import DockerEnvironment
from ag2.tools import AnthropicBashTool

bash = AnthropicBashTool(
    DockerEnvironment(image="python:3.12-slim", network_mode="none"),
    allowed=["ls", "cat", "python"],
    ignore=["**/.env", "*.key"],
)
Parameter Description
environment Execution backend (LocalEnvironment, DockerEnvironment, DaytonaEnvironment, TenkiEnvironment, or a custom one). None means a local subprocess.
allowed Whitelist of command prefixes.
blocked Blacklist of command prefixes. Best-effort: it matches the head command only, so chaining bypasses it.
ignore Gitignore-style path patterns. A command referencing a matching path is refused.
readonly When True and allowed is unset, restricts to a built-in read-only command set (cat, ls, grep, …).

The semantics are identical to SandboxShellTool's — see Command Filtering for the details.

Which Anthropic tool runs shell commands#

Anthropic exposes bash twice, and the two are not interchangeable:

Runs where AG2 tool
bash_20250124 On your machine, in the environment you pass AnthropicBashTool
bash inside code_execution_* In Anthropic's container CodeExecutionTool

Pick CodeExecutionTool when a throwaway sandbox on Anthropic's side is enough; pick AnthropicBashTool when the commands must act on your own files.

Note

Each command runs in a fresh sandbox, so there is no session to carry over. When the model asks for a restart, AG2 answers that there was nothing to restart rather than report a restart that never happened.

Note

AnthropicBashTool is Anthropic-only; other providers reject the schema with UnsupportedToolError. For a client-executed shell that works everywhere, use SandboxShellTool.

Warning

AnthropicBashTool executes model-authored commands on your machine. Use it only with trusted prompts, and prefer a container environment together with an allowed list.

Provider Skills#

SkillsTool activates skills that are hosted and executed by the provider — packaged capabilities such as spreadsheet or document generation. Pass skill ids as strings, or Skill objects to pin a version.

Note

Provider skills are unrelated to AG2's local Skills (SkillPlugin / SkillsToolkit), which run on your machine. SkillsTool only tells the provider which of its own skills to enable server-side.

1
2
3
4
5
6
7
8
9
from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import Skill, SkillsTool

agent = Agent(
    "analyst",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[SkillsTool("pptx", Skill("xlsx", version="latest"))],
)
1
2
3
4
5
6
7
8
9
from ag2 import Agent
from ag2.config import OpenAIResponsesConfig
from ag2.tools import SkillsTool

agent = Agent(
    "analyst",
    config=OpenAIResponsesConfig(model="gpt-5.4"),
    tools=[SkillsTool("openai-spreadsheets")],
)

Skills never appear as standalone entries in the provider's tools[] array — each client wires them into the request differently:

  • Anthropic — skills ride the container API parameter. They execute inside the code-execution container, so a CodeExecutionTool is added automatically when missing, along with the required beta headers. First-party skill ids: pptx, xlsx, docx, pdf.
  • OpenAI (Responses API) — skills attach to the hosted shell tool's container_auto environment as skill_reference entries; a shell tool is added automatically when missing. System skill ids carry the openai- prefix (e.g. openai-spreadsheets). Combining SkillsTool with ContainerReferenceEnvironment raises an error — skills for an existing container are configured when the container is created.

Version pins are strings. For Anthropic, a version date such as "20251013" or "latest" (None is sent as "latest"). For OpenAI, a positive integer such as "2" or "latest" (None omits the field, meaning the skill's default version).

MCP Server#

Integrates external MCP (Model Context Protocol) servers, giving the model access to remote tools.

from ag2 import Agent
from ag2.config import AnthropicConfig
from ag2.tools import MCPServerTool

agent = Agent(
    "assistant",
    config=AnthropicConfig(model="claude-sonnet-5"),
    tools=[
        MCPServerTool(
            server_url="https://mcp.example.com/sse",
            server_label="my-tools",
            allowed_tools=["search", "summarize"],
        ),
    ],
)
Parameter Anthropic OpenAI xAI
server_url ✓ ✓ ✓
server_label ✓ ✓ ✓
authorization_token ✓ ✓ ✓
description ✓ ✓ ✓
allowed_tools ✓ ✓ ✓
blocked_tools ✓ ✗ ✗
headers ✗ ✓ ✓

Image Generation#

ImageGenerationTool instructs the model to generate images inline during a conversation. Generated images are returned via reply.files.

from ag2 import Agent
from ag2.config import OpenAIResponsesConfig
from ag2.tools import ImageGenerationTool

agent = Agent(
    "designer",
    config=OpenAIResponsesConfig(model="gpt-4.1"),
    tools=[
        ImageGenerationTool(
            quality="high",
            size="1024x1024",
            output_format="png",
            background="transparent",
        ),
    ],
)

reply = await agent.ask("Generate a logo for a coffee shop.")
for image in reply.files:
    print(image.metadata.get("media_type"), len(image.data))

Note

ImageGenerationTool is only supported by OpenAI (Responses API). Gemini generates images through a response modality rather than a tool. See Image Generation for the full guide covering both providers.

XSearchTool gives xAI's Grok models real-time search over X (Twitter), optionally scoped to specific handles, a date range, or media understanding. This tool is xAI-specific.

from datetime import datetime

from ag2 import Agent
from ag2.config import XAIConfig
from ag2.tools import XSearchTool

agent = Agent(
    "researcher",
    config=XAIConfig(model="grok-4"),
    tools=[
        XSearchTool(
            allowed_x_handles=["xai"],
            from_date=datetime(2024, 1, 1),
            enable_image_understanding=True,
        ),
    ],
)
Parameter Description
allowed_x_handles Restrict the search to these X handles.
excluded_x_handles Exclude these X handles from results.
from_date / to_date Bound the search to a datetime range.
enable_image_understanding Let the model interpret images in posts.
enable_video_understanding Let the model interpret videos in posts.

Note

XSearchTool is only supported by xAI.

Retrieval#

RetrievalTool lets the model query a Z.AI knowledge base by id, grounding its answers in the retrieved documents.

from ag2 import Agent
from ag2.config import ZAIConfig
from ag2.tools.builtin import RetrievalTool

agent = Agent(
    "researcher",
    config=ZAIConfig(model="glm-4.6"),
    tools=[
        RetrievalTool(
            knowledge_id="kb_123",
            prompt_template="Use {{ knowledge }} to answer {{ question }}.",
        ),
    ],
)
Parameter Description
knowledge_id Required. Id of the Z.AI knowledge base to query.
prompt_template Optional template for injecting retrieved content, using {{ knowledge }} and {{ question }} placeholders.

Note

RetrievalTool is only supported by Z.AI.

Anthropic Tool Versions#

Anthropic versions their server-side tools. Newer versions support dynamic filtering (Claude writes code to filter results before loading into context), but require Opus 4.6 or Sonnet 4.6.

Set the version on each built-in tool (defaults match the older Anthropic tool revisions):

1
2
3
4
5
6
from ag2.tools import WebFetchTool, WebSearchTool

tools = [
    WebSearchTool(version="web_search_20260209"),  # default: web_search_20250305
    WebFetchTool(version="web_fetch_20260209"),    # default: web_fetch_20250910
]

The default versions are compatible with all Claude models including Haiku.