Add a custom Python tool to an AG2 Agent using the @tool decorator. Use when the user wants to give an Agent a new capability backed by Python code (API calls, DB queries, computations, file ops). Covers sync and async tools, parameter typing, Pydantic schema customisation, returning typed Input / ToolResult (text /…
Expose an AG2 Agent over the AG-UI protocol so a frontend (CopilotKit, custom React/Next.js, or any AG-UI client) can stream responses (text and reasoning), render tool calls, sync shared state, and track sub-task steps. Wraps the agent with AGUIStream(agent) and mounts it in FastAPI via stream.dispatch(...) or…
Compare AG2 agents, models, or prompts to decide which is better. runvariants scores several named agents on one suite and ranks them on a leaderboard (Variants holds a mapping of named Agent instances plus an axis label). runpairwise with pairwisejudge does head-to-head LLM comparison using a dual-order position swap…
Evaluate, test, and track an AG2 Agent offline. Build a Suite of tasks, run the agent with runagent, and grade answers with prebuilt scorers (finalanswermatches, toolcalled, notoolerrors, tokenbudget) or a custom @scorer — including the agentjudge LLM judge. Read the RunResult scorecard (passrate, scorestats…
Pause an AG2 Agent mid-run to collect human input via context.input(), or gate a tool call with approvalrequired() middleware. Use when the user wants the agent to ask for confirmation, request missing info (passwords, API keys, data), or have a human approve sensitive / irreversible / expensive tool calls (sending…
Persist agent state across runs, shape what the LLM sees per turn, and cap history to fit a context window. Covers KnowledgeStore (memory / sqlite / disk / redis), KnowledgeConfig (store=, exposetool=, writeeventlog=, compact=, aggregate=, bootstrap=) and its opt-out flags, aggregation strategies…
Build realtime voice / live audio agents with AG2's ag2.live module. Wrap a prompt + provider config in LiveAgent and open a bidirectional voice session with agent.run(), pumping mic audio in and playing synthesized speech out. Covers the two realtime providers — Gemini Live (GeminiRealTimeConfig) and OpenAI Realtime…
Host an MCP server that exposes an AG2 Agent (plus prompts and resources) to MCP clients like Claude Desktop, Cursor, or the MCP Inspector. Wrap the agent with MCPServer(agent) — it surfaces Agent.ask() as a single conversational tool and serves over stdio (runstdio()) or streamable HTTP (it is itself an ASGI app for…
Intercept the AG2 agent loop with BaseMiddleware — wrap full turns (onturn), each LLM call (onllmcall), each tool execution (ontoolexecution), or each human-input request (onhumaninput). Use for retry, logging, history trimming, request mutation, tool auditing, guardrails, or rate limiting. Built-ins…
Send images, audio, video, or documents into an AG2 Agent alongside text. Pass ImageInput, AudioInput, VideoInput, or DocumentInput as positional args to agent.ask(...). Use when the user wants the agent to process non-text input — describe a photo, transcribe audio, summarise a PDF, analyse a video. Covers…
Open an AG2 network discussion channel — N-party (2+) round-robin where each participant speaks in fixed order, cycling until explicit close or TTL. Use when the user wants a brainstorm with a fixed cast, a panel discussion, or round-robin reviewers. Covers agentclient.open(type="discussion", target=[...]…
Build a multi-agent AG2 network — load this whenever two or more Agents need to interact. The network is the standard multi-agent pattern in ag2. Covers Hub.open, LocalLink, HubClient.register, Passport, Resume, channel lifecycle (PENDING → ACTIVE → CLOSING → CLOSED), the two 2-party channel adapters (consulting for…
Shape what an AG2 network agent perceives and which actions its LLM can take. Covers the five auto-injected LLM-facing tools that ship via NetworkPlugin (delegate, peers, channels, tasks, context) plus the adapter-owned say; replacing the default handler with agentclient.onenvelope(callback) (gateways, headless…
Build an AG2 network workflow channel — the orchestrated N-party adapter driven by a declarative TransitionGraph. Use when the user needs conditional handoffs, multi-step pipelines, context-aware routing, feedback loops, or is migrating from the classic GroupChat + Agent.handoffs pattern. Covers TransitionGraph…
Map of AG2 capabilities and which sibling skill to reach for. Load first when the user mentions building with AG2 (ag2) but the specific feature isn't yet clear — agents, tools, model config, delegation, memory, observers, structured output, HITL, AG-UI, MCP server hosting, A2A protocol, realtime voice, telemetry…
Build a minimal AG2 Agent end to end — pick a model provider, set a prompt, call agent.ask(), then continue the conversation with reply.ask() (multi-turn). Use when the user is starting a new AG2 project, has no working Agent yet, or needs the multi-turn chaining pattern. Covers OpenAIConfig, AnthropicConfig…
Give an AG2 Agent the ability to run shell commands. Covers SandboxShellTool (client-side subprocess via LocalEnvironment, works with any provider) and the provider-native ShellTool (OpenAI Responses execution). Use when the user wants the Agent to execute commands, build/test code, manage files, or operate on a…
Get a typed Python value back from an AG2 Agent instead of free text. Pass responseschema= (a Pydantic model, dataclass, primitive, union, ResponseSchema, or @responseschema validator) and read the parsed result via await reply.content(). Use when the user wants validated structured output, classification, extraction…
Single-agent recursion and parallel fan-out within one AG2 Agent — auto-injected runsubtask / runsubtasks(parallel=True) (opt in via tasks=TaskConfig(...)) for self-delegation, and Agent.astool() as a lightweight no-hub way to call one named agent from inside another. Use when a single coordinator wants to break work…
Add OpenTelemetry traces to an AG2 Agent via TelemetryMiddleware (ag2.middleware.builtin). Emits spans for the full turn, each LLM call, each tool execution, and each human-input request, following the OpenTelemetry GenAI semantic conventions. Compatible with any OTLP backend — Jaeger, Grafana Tempo, Datadog…
Test AG2 agents and tools without hitting a real LLM provider. Pass TestConfig(...) from ag2.testing as the agent's config (or per-ask) to mock LLM responses, inject ToolCallEvents to simulate tool execution, and assert success / error paths. Use when the user is writing pytest tests for an Agent or Tool.
Wire AG2's shipped tools into an Agent — both provider-native server-side tools (web search, web fetch, code execution, MCP, image generation, memory) and locally-executed common toolkits (filesystem, DuckDuckGo, Exa, Tavily, skills). Use when the user wants capabilities AG2 already ships rather than writing custom…