Komut#buildwithclaude
0
New tool
Tür ek açıklamaları, belge dizeleri ve JSON iade sözleşmeleriyle bir AG2 aracısı için bir araç işlevi oluşturun
yazan kuscubasiece·8 Eylül 2026
Kaynak: davepoon/claude-code-subagents-collection · MIT
Tür ek açıklamaları, belge dizeleri ve JSON iade sözleşmeleriyle bir AG2 aracısı için bir araç işlevi oluşturun
Kaynak: davepoon/claude-code-subagents-collection · MIT
mkdir -p .claude/commands && curl -sL https://www.antrophiclove.com/api/kaynak/new-tool/raw -o .claude/commands/new-tool.mdHedef dosya: .claude/commands/new-tool.md
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 format: Always a JSON string with this structure:
{"success": true, "data": { ... }}
{"success": false, "error": "Human-readable error message"}
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:
Exception{"success": false, "error": "connector_setup_required:<connector_id>"}# BAD: Returns dict instead of JSON string
@tool()
def bad_tool(x: str) -> dict:
return {"result": x}
# BAD: No type annotations
@tool()
def bad_tool(x):
return json.dumps({"success": True})
# BAD: Raises exception instead of returning error
@tool()
def bad_tool(x: str) -> str:
result = api_call(x) # Can raise!
return json.dumps({"success": True, "data": result})
# 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})