Common Tools#
AG2 ships with ready-made tools and toolkits that bundle related function tools into a single Toolkit. Unlike built-in provider tools, these run locally as regular Python functions and work with every provider.
FilesystemToolkit#
FilesystemToolkit gives an agent the ability to read, write, update, delete, and search files within a sandboxed directory. All paths are resolved relative to a configurable base_path, and a path-traversal guard prevents access outside it.
Available tools#
| Tool | Description |
|---|---|
read_file | Read the contents of a file |
write_file | Create or overwrite a file (creates parent directories automatically) |
update_file | Replace the first occurrence of a string in a file |
delete_file | Delete a file |
find_files | Search for files matching a glob pattern (supports recursive ** patterns) |
Read-only mode#
Pass read_only=True to expose only read_file and find_files:
Using individual tools#
Every tool is available as an attribute on the toolkit instance. You can pass individual tools to an agent instead of the whole set:
Using a temporary directory#
For throwaway workspaces, use tempfile.TemporaryDirectory so the directory and all its contents are automatically cleaned up when the context manager exits:
Tip
Prefer tempfile.TemporaryDirectory over hardcoded /tmp paths. It guarantees a unique directory per run and cleans up after itself, avoiding leftover files and collisions between concurrent executions.
Path safety#
All paths are resolved relative to base_path. Any attempt to escape the base directory (e.g. ../../etc/passwd) raises a PermissionError:
SkillsToolkit#
SkillsToolkit gives an agent access to locally installed skills following the agentskills.io convention. Each skill is a directory containing a SKILL.md instructions file and an optional scripts/ subdirectory of runnable .py / .sh files.
The toolkit uses a three-step progressive-disclosure pattern so the agent fetches only the detail it actually needs:
list_skills— returns a lightweight catalog (name + description).load_skill— returns the fullSKILL.mdinstructions for a specific skill on demand.run_skill_script— executes a script from the skill'sscripts/directory.
By default SkillsToolkit looks for skills in .agents/skills relative to the current working directory.
Custom install directory#
Pass a LocalRuntime to point to a different directory:
Extra read-only search paths#
extra_paths adds additional directories that are scanned for skills but never written to — installed skills always go to the primary dir:
Using individual tools#
Every tool is available as an attribute on the toolkit instance:
Available tools:
| Tool | Description |
|---|---|
list_skills | Return a catalog of installed skills with name and short description |
load_skill | Fetch the full SKILL.md content for a specific skill |
run_skill_script | Execute a .py or .sh script from a skill's scripts/ directory |
SkillSearchToolkit#
SkillSearchToolkit extends SkillsToolkit with three additional tools for discovering and installing skills from the skills.sh registry. It uses the GitHub Tarball API directly — no Node.js required.
GitHub rate limits#
By default the GitHub API allows 60 unauthenticated requests per hour. Setting a GITHUB_TOKEN environment variable raises this to 5,000 per hour:
You can also pass the token directly via SkillsClientConfig:
Custom configuration#
Using individual tools#
Available tools:
SkillSearchToolkit inherits all tools from SkillsToolkit and adds:
| Tool | Description |
|---|---|
search_skills | Search the skills.sh registry by keyword |
install_skill | Download and install a skill by its registry identifier |
remove_skill | Remove an installed skill by name |
DuckDuckSearchTool#
DuckDuckSearchTool gives an agent the ability to search the web using DuckDuckGo. No API key is required.
Note
Requires the ddgs extra: pip install ag2[ddgs]
Configuration#
All parameters accept a Variable for dynamic values resolved at execution time.
ExaToolkit#
ExaToolkit gives an agent four related tools powered by the Exa neural search engine: web search, find-similar, content retrieval, and AI-powered answers — all sharing a single client.
Note
Requires the exa extra and an API key: pip install ag2[exa]
If api_key is omitted, the Exa SDK reads EXA_API_KEY from the environment automatically.
Tools#
| Tool | Description |
|---|---|
exa_search | Neural web search with filters (domains, dates, type, category) |
exa_find_similar | Find pages similar to a given URL |
exa_get_contents | Fetch full text content for specific URLs |
exa_answer | Get an AI-generated answer with citations |
Shared defaults#
num_results and max_characters on the constructor are applied to the default exa_search and exa_find_similar tools:
Picking a subset of tools#
Each tool is exposed as a factory method on the toolkit (toolkit.search(), toolkit.find_similar(), toolkit.get_contents(), toolkit.answer()). Call the method to get a ready-to-use tool, then pass only the ones you need to the agent:
Per-tool configuration#
Per-call parameters (filters, domains, dates, num_results, max_characters, etc.) live on the factory methods, not on the toolkit itself:
When max_characters is set, exa_search calls Exa's search_and_contents endpoint so each result carries text. When max_characters is None, only metadata is returned (cheaper and faster).
All runtime parameters accept Variable for deferred context resolution.
PerplexitySearchToolkit#
PerplexitySearchToolkit gives an agent two related tools powered by Perplexity: raw web search via the Search API and LLM-grounded answers with citations via Sonar — sharing a single client.
Note
Requires the perplexity extra and an API key: pip install ag2[perplexity]
If api_key is omitted, the Perplexity SDK reads the PERPLEXITY_API_KEY environment variable automatically.
Tools#
| Tool | Description |
|---|---|
perplexity_search | Raw web search via the Search API — ranked title/url/snippet/date results, no LLM hop |
perplexity_answer | LLM-generated answer with citations via Sonar Chat Completions — also returns search results, citations, and optional images |
Picking a subset of tools#
Each tool is exposed as a factory method on the toolkit (toolkit.search(), toolkit.answer()). Call the method to get a ready-to-use tool, then pass only the ones you need to the agent:
Per-tool configuration#
Per-call parameters live on the factory methods, not on the toolkit itself:
All runtime parameters accept a Variable for deferred context resolution.
HTTP and SDK options#
The toolkit constructor accepts options for the underlying httpx.AsyncClient and the Perplexity SDK client. Any extra keyword arguments are forwarded directly to AsyncPerplexity(...) (e.g. base_url, max_retries, default_headers):
Result#
Both tools return a PerplexitySearchResponse with these fields:
| Field | Description |
|---|---|
query | The original search query |
results | List of PerplexitySearchResult (title, url, snippet, date) |
content | LLM-generated answer (filled by perplexity_answer; empty for perplexity_search) |
citations | URLs the model cited inline (filled by perplexity_answer) |
images | List of PerplexityImageMeta when return_images=True on perplexity_answer |
When return_images=True, image URLs are also surfaced as ImageInput parts on the tool result so the next model turn receives them as proper image inputs.
Tip
Use perplexity_search when the agent only needs raw ranked URLs (cheaper, no LLM hop). Use perplexity_answer when a grounded answer with citations is helpful.
Tip
search_domain_filter on perplexity_answer is a Pro-tier feature on the Perplexity API; see usage tiers.
TavilySearchTool#
TavilySearchTool gives an agent advanced web search capabilities via the Tavily API. Results include relevance scores and optional LLM-generated answers, raw page content, and images.
Note
Requires the tavily extra and an API key: pip install ag2[tavily]
If api_key is omitted, Tavily reads the TAVILY_API_KEY environment variable automatically.
Configuration#
All search parameters accept a Variable for dynamic values resolved at execution time.
HTTP and SDK options#
The constructor also accepts options for the underlying httpx.AsyncClient and the Tavily SDK client. Any extra keyword arguments are forwarded directly to AsyncTavilyClient(...) (e.g. api_base_url, company_info_tags, project_id):
LocalShellTool#
LocalShellTool gives an agent the ability to run shell commands in a local subprocess. By default it creates a temporary working directory that is cleaned up on process exit.
Warning
LocalShellTool executes arbitrary shell commands. Use allowed, blocked, or readonly to restrict what the agent can run.
Passing a path string creates a LocalShellEnvironment in that directory. Passing nothing creates a temporary directory.
Restricting commands#
Use LocalShellEnvironment directly to control what the agent can run: