$ show ag2ai/ag2
AG2 is a production-grade Python framework for building multi-agent AI systems. It provides a unified agent abstraction with support for multiple LLM providers (OpenAI, Anthropic, Gemini, Mistral, Bedrock, Ollama, xAI, Z.AI, DashScope), protocol integrations (A2A, A2UI, MCP, ACP), and sandboxed code execution (Docker, Daytona, local). The architecture is event-driven with a modular middleware pipeline, dependency injection, and a streaming event bus. It includes a full evaluation suite with trace reconstruction, scorers, pairwise comparison, and result persistence. The network layer enables distributed agent coordination via a hub-and-channel model with WAL persistence, identity management, and transport-agnostic envelopes. The framework also supports real-time voice interaction, skills-based toolkits, knowledge stores, and human-in-the-loop workflows. While the surface area is large, the codebase demonstrates high craftsmanship with clean abstractions, protocol-based interfaces, and extensive test coverage across all modules.
The LLM identified 7 files worth highlighting for reuse:
Base event class hierarchy with Field metadata, transient/conversational flags, custom serialization (including bytes, UUIDs, enums, Pydantic models, nested events). Implements a reusable pattern for typed event systems that can be extended by any application needing structured event streams with serialization and conditional filtering.
Defines BaseMiddleware with lifecycle hooks (on_turn, on_llm_call, on_tool_execution, on_human_input) and MiddlewareFactory for per-turn middleware composition. Provides DescribableMiddleware mixin for self-description. This is a clean, protocol-based middleware pattern that can be extracted for any system requiring interceptor chains.
FunctionTool class that wraps callables with automatic JSON schema generation, middleware propagation, and type validation. The @tool decorator creates FunctionTool instances. This pattern decouples tool implementation from agent integration and is reusable across any agent framework needing typed function tools.
Implements failure attribution scoring with deterministic detectors (crash, no_answer, tool_failure) and an optional LLM-based attributor. Returns structured Feedback with named failures. This pattern is reusable for any evaluation pipeline needing to attribute agent failures to root causes.
SandboxBase protocol defining exec, put_file, remove_file, and async context manager interface. Combined with SandboxFactory (caching, per-call) and ShellAdapter/CodeAdapter, this provides a clean abstraction over execution environments (local, Docker, Daytona). The protocol pattern allows easy addition of new sandbox backends.
MemoryKnowledgeStore implementing the KnowledgeStore protocol with in-memory storage, versioning, change watchers, and index scanning. Paired with DiskKnowledgeStore, RedisKnowledgeStore, and SqliteKnowledgeStore, this forms a pluggable storage abstraction that can be reused for any application needing a hierarchical key-value store with change notifications.
Implements pairwise judge scoring with dual-order swap to mitigate position bias. Uses an LLM-as-judge to compare two agent responses and returns structured Feedback with win/lose/tie. The pattern includes trajectory rendering and telemetry middleware. This is a reusable evaluation technique for any LLM-based system requiring comparative judgment.