用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ag2ai/resource-hub --skill agent-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | agent-patterns |
| description | Patterns for creating and configuring AG2 agents correctly |
| license | Apache-2.0 |
Always use the LLMConfig context manager. Agents created inside its scope inherit the configuration automatically.
from ag2 import LLMConfig
from ag2.agentchat import AssistantAgent, UserProxyAgent
with LLMConfig(api_type="openai", model="gpt-4o"):
planner = AssistantAgent(
name="planner",
system_message="You are a project planner. Break tasks into steps.",
)
reviewer = AssistantAgent(
name="reviewer",
system_message="You review plans for completeness and correctness.",
)
executor = UserProxyAgent(
name="executor",
human_input_mode="NEVER",
code_execution_config={"work_dir": "workspace"},
)
Agents that do not need an LLM (e.g., pure code executors) should be created outside the context manager.
# Good
system_message = (
"You are a SQL analyst. Write SQL queries to answer user questions. "
"Only use SELECT statements. Never modify data."
)
# Bad -- too vague
system_message = "You are a helpful assistant."
data_analyst, code_reviewer.assistant or agent1.Register tools on the agents that should be able to call and execute them:
from ag2.tools import tool
@tool
def search_database(query: str, limit: int = 10) -> str:
"""Search the database and return matching rows."""
# implementation
return results
analyst = AssistantAgent(name="analyst", system_message="...")
executor = UserProxyAgent(name="executor", human_input_mode="NEVER")
# Register: analyst decides when to call, executor runs the function
analyst.register_tool(search_database, caller=analyst, executor=executor)
"ALWAYS" -- Ask for human input on every turn."TERMINATE" -- Ask only when the agent wants to terminate."NEVER" -- Fully autonomous, no human input.# Autonomous executor
executor = UserProxyAgent(name="executor", human_input_mode="NEVER")
# Human-in-the-loop
user = UserProxyAgent(name="user", human_input_mode="TERMINATE")
Agents stop when a reply contains "TERMINATE". Configure this in the system message:
system_message = (
"You solve math problems. When you have the final answer, "
"reply with TERMINATE."
)