ag2
БесплатноБез исполняемых скриптовНе проверенAG2 (formerly AutoGen) is an open-source Python framework for building AI agents and multi-agent systems that use tools, human approval and structured…
Об этом скилле
AG2 (AutoGen) — Multi-Agent Conversation Framework
Overview
AG2 is the community continuation of Microsoft's AutoGen. Since v1.0 (current: 1.1.1, September 2026) it is a new, async-first framework and is not backward compatible with classic AutoGen:
| You see in code | You have | Install |
|---|---|---|
from ag2 import Agent, from ag2.config import OpenAIConfig |
AG2 v1 | pip install "ag2[openai]" |
from autogen import ConversableAgent, GroupChat, UserProxyAgent |
classic AutoGen / AG2 0.x | pip install ag2-classic (its README also shows autogen[openai]) |
Classic is in maintenance mode (security fixes only). Do not mix the two APIs in one file. Provider extras for v1: ag2[openai], ag2[anthropic], ag2[gemini], ag2[ollama] and others. Docs: https://docs.ag2.ai (v1) and https://classic.docs.ag2.ai (classic).
Instructions
AG2 v1: an agent with a tool
import asyncio
from ag2 import Agent, tool
from ag2.config import OpenAIConfig # also AnthropicConfig, GeminiConfig, OllamaConfig, ...
@tool
async def count_lines(path: str) -> str:
"""Count the lines in a source file inside the current project."""
with open(path, encoding="utf-8") as f:
return f"{path}: {sum(1 for _ in f)} lines"
reviewer = Agent(
"reviewer",
prompt="You review Python code. Use tools to inspect files before judging them.",
config=OpenAIConfig("gpt-4o-mini"), # key is read from OPENAI_API_KEY
tools=[count_lines],
)
async def main() -> None:
reply = await reviewer.ask("How big is app/main.py?")
print(reply.body)
follow_up = await reply.ask("Is that too large for one module?") # keeps the history
print(follow_up.body)
asyncio.run(main())
agent.ask(...)returns a reply;reply.bodyis the text andreply.ask(...)continues the same conversation.- A tool is a typed function with a docstring decorated with
@tool; the signature and docstring become the schema the model sees. - Stream or observe a turn with
async with agent.run("...") as run: run.start(); async for event in run.stream...andawait run.result(). - Human approval: pass
hitl_hook=toAgent; it receives aHumanInputRequest(fromag2.events) and returns aHumanMessage(content=...). - Test without an LLM:
from ag2.testing import TestConfigand passTestConfig("scripted reply")(orToolCallEvents) asconfig.
AG2 v1: several agents
v1 replaces GroupChat, swarm and nested chats with a Network: a Hub registers agents, and they talk over typed channels (conversation for free two-party chat, consulting for one question and one answer, discussion for round-robin among N agents, workflow for a TransitionGraph of conditional handoffs, the closest analogue to GroupChat). Read the group-chat migration guide on docs.ag2.ai before writing this part; the classes live in ag2.network (Hub, Channel, TransitionGraph, Handoff).
Classic AutoGen (ag2-classic): two agents and group chat
Only for existing code that imports autogen.
from autogen import ConversableAgent, LLMConfig, UserProxyAgent, register_function
from autogen.agentchat import run_group_chat
from autogen.agentchat.group.patterns import AutoPattern
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini") # key from OPENAI_API_KEY
engineer = ConversableAgent(
name="engineer",
system_message="You write clean, tested Python. Explain design decisions briefly.",
llm_config=llm_config,
)
runner = UserProxyAgent(
name="runner",
human_input_mode="NEVER", # NEVER / ALWAYS / TERMINATE
max_consecutive_auto_reply=10,
is_termination_msg=lambda m: "TERMINATE" in (m.get("content") or ""),
code_execution_config={"work_dir": "workspace", "use_docker": True},
)
result = runner.initiate_chat(engineer, message="Write a FastAPI /health endpoint with a pytest test.", max_turns=6)
reviewer = ConversableAgent(name="reviewer", system_message="You review code for bugs and security issues.", llm_config=llm_config)
pattern = AutoPattern(
agents=[engineer, reviewer],
initial_agent=engineer,
group_manager_args={"name": "manager", "llm_config": llm_config},
)
response = run_group_chat(pattern=pattern, messages="Build a rate limiter for our API.", max_rounds=12)
Tools in classic: register_function(fn, caller=engineer, executor=runner, description="..."). The caller proposes the call, the executor runs it. Classic also has LLMConfig.from_json(path="OAI_CONFIG_LIST") for a config file. Only the register and run_group_chat calls above were checked against the classic README; check other classic details at classic.docs.ag2.ai.
Examples
Example 1: Single agent that inspects a repository
User request: "Make me an AG2 agent that can count lines in files and answer questions about them."
Install with python -m venv .venv && .venv/bin/pip install "ag2[openai]", save the v1 code above a
Установить ag2 в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл ag2?
AG2 (formerly AutoGen) is an open-source Python framework for building AI agents and multi-agent systems that use tools, human approval and structured conversations. Use it when you need agents that call functions, collaborate in a group chat, execute code, or when you are migrating AutoGen or pyautogen code to AG2 v1 or ag2-classic.
Как установить скилл ag2?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ag2 запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic