From ag2-tool-builder
Create a new tool function for an AG2 agent. Generates properly typed, documented tool functions with JSON return contracts and error handling.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ag2-tool-builder:new-toolThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are creating tool functions for AG2 agents. Tools are how agents interact with external systems.
You are creating tool functions for AG2 agents. Tools are how agents interact with external systems.
Ask the user for:
Generate the tool following this exact contract:
import json
from autogen.tools import tool
@tool()
def tool_name(required_param: str, optional_param: int = 10) -> str:
"""Clear, specific description of what this tool does.
The docstring becomes the function description in the LLM's tool schema.
Be specific about what the tool returns and when to use it.
Args:
required_param: What this parameter is for
optional_param: What this controls (default: 10)
"""
try:
# Implementation here
result = {
"items": [],
"total_count": 0,
"metadata": {},
}
return json.dumps({"success": True, "data": result})
except ValueError as e:
return json.dumps({"success": False, "error": f"Invalid input: {e}"})
except Exception as e:
return json.dumps({"success": False, "error": str(e)})
Return types: Tool functions can return:
str -- plain text or JSON stringspydantic.BaseModel -- automatically serialized by the frameworkReplyResult -- for group chat tool-based handoffs (includes target for routing)The JSON {"success": true, "data": ...} pattern shown above is a good convention for structured tools but is NOT required.
Type annotations: All parameters MUST have type annotations. The LLM uses these to construct calls.
Docstrings: MUST include:
Args: section describing each parameterParameter design:
str, int, float, boolstr for complex inputs (JSON strings) -- avoid nested objectsError handling:
"Error: {message}" strings{"success": false, "error": "connector_setup_required:<connector_id>"}# BAD: No type annotations
@tool()
def bad_tool(x):
return json.dumps({"success": True})
# BAD: No docstring
@tool()
def bad_tool(x: str) -> str:
return json.dumps({"success": True})
# BAD: Vague docstring
@tool()
def bad_tool(x: str) -> str:
"""Does stuff.""" # LLM won't know when to use this
return json.dumps({"success": True})
npx claudepluginhub ag2ai/ag2-claude-plugins --plugin ag2-tool-builderGuides Python tool development for Atomic Agents: BaseTool templates, Pydantic schemas, config, error handling, and agent integration.
Guides tool design for AI agents, covering JSON Schema, descriptions, validation, error handling, and the MCP standard.
Generates boilerplate for custom @tool-decorated functions in Claude Agent SDK, including MCP server setup and agent config. Use when adding tools to custom agents.