How ag2ai/ag2 works
Project type and purpose
• This is a library/framework (AG2, formerly AutoGen) for building and orchestrating AI agents in Python. It is not a web or mobile app but an open-source AgentOS providing core agent abstractions, multi-agent orchestration patterns (conversable agents, group chat, swarms), tool registration/execution, LLM client integrations, RAG, caching, code execution environments, and extensive documentation/notebooks.
High-level analysis of the file structure
• Top-level directories:
• autogen/ → Main Python package: core, agentchat, tools, interop, cache, coding, events, oai (LLM clients), mcp (FastAPI proxy), io, logger, etc.
• test/ → Automated tests for every submodule.
• notebook/ → Jupyter notebooks demonstrating use cases.
• website/ → Documentation site source (MkDocs, Docusaurus, scripts).
• scripts/ → Build, test, lint, devcontainer utilities.
• Key patterns:
• Core agent abstractions under autogen/agentchat and autogen/agents.
• Tooling modules for external APIs and code execution under autogen/tools and autogen/coding.
• LLM client abstractions under autogen/oai and autogen/interop.
• Caching layer (disk, Redis, Cosmos, in-memory) under autogen/cache.
• Orchestration patterns (GroupChat, Swarm) under autogen/agentchat/group.
• Event and message pipelines under autogen/events and autogen/messages.
• Configuration/CI: devcontainer, GitHub Actions workflows, pre-commit config, pyproject.toml.
Insights from the README
• Project goal: streamline building single and multi-agent workflows, integrate human-in-the-loop, various LLM providers, tools, RAG, and advanced patterns.
• Core concepts: ConversableAgent, UserProxyAgent, GroupChat, Swarm, tool registration, structured outputs, retrieval, code execution.
• External dependencies: Python ≥3.9, LLM provider APIs (OpenAI, Anthropic, Gemini, etc.), vector stores (Chroma, Qdrant, MongoDB), Docker for code execution.
a. Main components
1. Core Agent Framework (autogen/)
• Agent abstractions (ConversableAgent, AssistantAgent, UserProxyAgent)
• Multi-agent orchestrators (GroupChatManager, Swarm)
• Message/event pipeline
2. LLM Client Layer (autogen/oai + autogen/interop)
• OpenAI, Anthropic, Gemini, Bedrock, Cohere, Mistral, etc.
3. Tooling Layer
• Registered “tool” functions (autogen/tools)
• Code execution environments (Docker, local, Jupyter) under autogen/coding and autogen/environments
4. Retrieval & Caching
• Vector stores (ChromaDB, Qdrant, MongoDB) under autogen/agentchat/contrib/* and autogen/interop
• Cache backends (in-memory, disk, Redis, CosmosDB) under autogen/cache
5. Logging & Monitoring
• Logger factories (file, SQLite) under autogen/logger
• Runtime event logging (autogen/events, autogen/io/processors)
6. Application Entry Points
• CLI (autogen mcp, scripts)
• Jupyter notebooks (notebook/)
7. Documentation Website
• MkDocs, Docusaurus sources in website/
b. Relationships and interactions
• Agent initiates message → Core framework routes to orchestrator or directly to recipient.
• Core framework invokes LLM Client → returns model-generated response.
• If the response indicates a tool call → Tooling Layer executes code or external API.
• Retrieval Layer handles RAG: query vector store, retrieve docs, feed to LLM.
• Caching Layer intercepts LLM and retrieval calls to store/serve cached results.
• Logging & Event layers subscribe to agent events, emit logs or CLI output.
• Orchestrators decide which agent speaks next or parallelize (swarm).
c. Architectural patterns and design principles
• Modular layering: clear separation of agent core, LLM clients, tools, retrieval, caching.
• Dependency injection: tool registration, pluggable LLM backends, environment abstraction.
• Event-driven messaging: agents communicate via a message/event bus.
• Extensibility: add new agents, tools, backends without changing core.
d. Key technologies/frameworks
• Python 3.9+
• FastAPI (mcp proxy)
• Docker (code execution environments)
• Vector DBs (Chroma, Qdrant, MongoDB)
• LLM SDKs (OpenAI, Anthropic, Gemini, etc.)
• MkDocs/Docusaurus (documentation)
Final advice
• Plugin points explicitly to show extensibility.
• Keep the focus on how messages traverse the system and how backends plug in.