用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ag2ai/resource-hub --skill add-tool命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | add-tool |
| description | How to create and register a tool on an AG2 agent |
| license | Apache-2.0 |
Use the @tool decorator. The function's docstring becomes the tool description the LLM sees. Use type annotations for all parameters.
from ag2.tools import tool
@tool
def get_weather(city: str, units: str = "celsius") -> str:
"""Get the current weather for a city.
Args:
city: Name of the city to look up.
units: Temperature units, either 'celsius' or 'fahrenheit'.
"""
# Your implementation here
return f"The weather in {city} is 22 {units}"
You need two agents:
from ag2 import LLMConfig
from ag2.agentchat import AssistantAgent, UserProxyAgent
with LLMConfig(api_type="openai", model="gpt-4o"):
assistant = AssistantAgent(
name="weather_assistant",
system_message="You help users check the weather. Use the get_weather tool.",
)
executor = UserProxyAgent(
name="executor",
human_input_mode="NEVER",
)
assistant.register_tool(get_weather, caller=assistant, executor=executor)
This tells AG2:
assistant can generate tool-call requests for get_weather.executor runs the actual function and returns the result.The @tool decorator inspects type annotations to build the JSON schema sent to the LLM. Always annotate parameters.
Supported types:
str, int, float, boollist[str], dict[str, int]Optional[str], or str | NoneLiteral["option_a", "option_b"]from typing import Literal
@tool
def query_db(
table: str,
columns: list[str],
limit: int = 100,
order: Literal["asc", "desc"] = "asc",
) -> str:
"""Query a database table and return results."""
# implementation
return "results"
from ag2 import LLMConfig
from ag2.agentchat import AssistantAgent, UserProxyAgent
from ag2.tools import tool
@tool
def search_docs(query: str, top_k: int = 5) -> str:
"""Search the documentation index.
Args:
query: The search query string.
top_k: Number of results to return.
"""
# Replace with real search logic
return f"Found {top_k} results for '{query}'"
@tool
def write_file(path: str, content: str) -> str:
"""Write content to a file.
Args:
path: File path to write to.
content: Content to write.
"""
with open(path, "w") as f:
f.write(content)
return f"Wrote {len(content)} chars to {path}"
with LLMConfig(api_type="openai", model="gpt-4o"):
assistant = AssistantAgent(
name="doc_writer",
system_message=(
"You help write documentation. Use search_docs to find relevant info, "
"then use write_file to save the output. Reply TERMINATE when done."
),
)
executor = UserProxyAgent(name="executor", human_input_mode="NEVER")
assistant.register_tool(search_docs, caller=assistant, executor=executor)
assistant.register_tool(write_file, caller=assistant, executor=executor)
result = assistant.initiate_chat(
executor,
message=,
)
基于 SOC 职业分类