Tools are the action layer of each agent. An agent can reason, plan, and generate text on its own — but every interaction with the outside world happens through a tool. Sending an email, reading a file, running a search query, calling an API — all of that is a tool call. OpenSwarm agents inherit from Agency Swarm’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/UnkleFunk/HouseMusicSwarm-/llms.txt
Use this file to discover all available pages before exploring further.
BaseTool, which means every tool you write is automatically available to the agent’s model as a structured function call with validated inputs.
Tool anatomy
Every tool in the codebase follows the same pattern: aBaseTool subclass with Pydantic fields for inputs and a run() method that does the work. Here is the actual WriteFile tool from virtual_assistant/tools/WriteFile.py:
ReadFile — the read counterpart — showing how Optional fields work and how the tool handles large files gracefully:
Tool requirements
Every tool in OpenSwarm follows these rules, drawn directly from the Agency Swarm framework and the codebase conventions:- Must inherit from
BaseTool— imported fromagency_swarm.tools. This is what registers the class as a callable function in the agent’s model context. - Must implement
run()— the method the framework calls when the agent invokes the tool. It must return a string (or something that stringifies cleanly). - All inputs are Pydantic fields — declare each input as a class attribute with
Field(...)(required) orField(default, ...)(optional). Pydantic validates inputs beforerun()is called, so you never receive the wrong type. - Never return binary data or base64 blobs — the return value lands in the agent’s context window. Return paths, summaries, or structured text instead.
- Always handle errors gracefully — return an error string rather than raising an exception. The agent can read the error message and decide what to do next.
- Include an
if __name__ == "__main__"test block — run the tool file directly (python agent_name/tools/MyTool.py) to verify it works before wiring it to an agent. - Read API keys from environment variables — never accept API keys as tool inputs. Use
os.getenv("MY_API_KEY")insiderun().
Shared tools
Theshared_tools/ directory contains tools that are available to every agent in the swarm without explicit per-agent registration. These are primarily Composio integration tools:
ManageConnections
ManageConnections
File:
shared_tools/ManageConnections.pyChecks whether the required external services (Gmail, Slack, Notion, etc.) are authenticated and connected for the current Composio user. This should always be the first tool called before any Composio workflow — it verifies the connection exists and triggers the OAuth flow if it doesn’t.Fields: toolkits (list of toolkit names to check), reinitiate_all (force reconnection), session_id (link to a previous search session).SearchTools
SearchTools
File:
shared_tools/SearchTools.pySearches the Composio tool registry by intent or use-case description and returns candidate tools with their schemas. Use this when you know what you want to do (e.g., “send an email”) but not the exact Composio tool name. Accepts a list of queries, each with at least a use_case key.FindTools
FindTools
File:
shared_tools/FindTools.pyFetches tools from Composio by toolkit name or exact tool name. Use this when you already know the toolkit (["GITHUB"]) or the exact tool (["GITHUB_CREATE_ISSUE"]). Set include_args=True to get the full parameter schema — only do this immediately before executing, to avoid wasting context tokens on schemas you won’t use.ExecuteTool
ExecuteTool
File:
shared_tools/ExecuteTool.pyExecutes a single Composio tool call and returns the result. Takes tool_name (exact Composio tool name), arguments (dict of parameters), and an optional return_fields list to extract only specific fields from the response and keep the context window clean.Use this for simple single-action tasks. For complex multi-step workflows requiring data transformation between steps, use IPythonInterpreter with programmatic Composio calls instead.Tools declared in
shared_tools/ are loaded into the agency-level shared context automatically when the Agency is constructed with shared_instructions="shared_instructions.md". Individual agents do not need to import or declare them — they are available to every agent in the swarm without any additional registration.