EventGet 50% off your ticket to MongoDB.local London on October 2. Use code WEB50Learn more >>
MongoDB Developer
Atlas
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Atlaschevron-right

Multi-agent Systems With AutoGen and MongoDB

Richmond Alake, Han Heloir10 min read • Published Sep 18, 2024 • Updated Sep 18, 2024
AIAtlasPython
Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Today, agentic AI is no longer a novel term for people interested in generative AI (gen AI). Agentic AI is an objective-driven artificial intelligence system that decomposes complex tasks, makes autonomous decisions, and executes actions using available tools or system components.  These systems are characterized as agents due to their ability to perceive context, reason about potential actions, and execute those actions to achieve specific goals.
There are several different types of agentic AI design patterns that are emerging, the notable ones being:
  1. Task-specific agents: These are designed to excel at a particular task or domain, such as language translation, image recognition, or financial analysis.
  2. Single-agent systems: These consist of a single AI agent with access to various tools and system components. The agent is responsible for understanding the task, planning the approach, and utilizing the appropriate tools to accomplish the goal.
  3. Hierarchical agents: These systems have a structure where higher-level agents delegate tasks to lower-level agents, mimicking organizational hierarchies.
What if you had not only one agent but multiple intelligent agents in one system? Like in a Kubernetes cluster, agents are orchestrated like containers to solve pronounced problems. Each agent, much like a Kubernetes pod, is designed for a specific task and collaborates to meet demand.
We're excited to announce that MongoDB has contributed to the AutoGen framework, enabling users to utilize MongoDB as a retrieval-augmented generation (RAG) agent within AutoGen. This integration empowers developers and data scientists to harness the power of MongoDB's scalable and flexible database capabilities in building generative AI multi-agent systems.
MongoDB AutoGen Integration workflow
What's covered in this article:
  • Integration of the multi-agent framework AutoGen with MongoDB
  • Creation of an innovative agentic system akin to a Kubernetes environment
  • Benefits of multi-agent systems in AI applications
  • Key capabilities and features of AutoGen
  • Advantages of MongoDB for robust data management in multi-agent systems
  • Practical insights on combining these technologies for enhanced AI solutions
All code is available in this GitHub repository.

Understanding multi-agentic AI systems

Multi-agent systems can be compared to human organization structure, such as a high-performing team collaborating on a complex product development project. In such a team, diverse roles come together, each contributing specialized expertise to ensure the product's success. This same principle of collaboration is mirrored in multi-agent AI systems, where distinct AI agents, each with unique capabilities, work together to achieve a common objective.
  • Product manager: Defines the product vision, strategy, and roadmap to ensure alignment with market needs and business objectives
  • Developer: Implements features, ensuring the application is robust and production-ready
  • Quality assurance engineer: Tests the product to ensure reliability and quality
Ensuring collaboration among agents enhances their functionality and broadens their range of applications. When agents work together, they can tackle complex tasks more efficiently than a single agent could on its own. This is true because collaboration among agents allows for specialization and division of labor, enabling each agent to focus on its strengths while compensating for others' limitations.
Before exploring AutoGen and the MongoDB integration, it's important to discuss the prominent frameworks used to build AI agents and agentic systems. This is particularly relevant because the agentic AI space can be considered to be in its infancy. Examining these frameworks will help highlight the key advantages of AutoGen for your specific use case.
Several frameworks have gained popularity for developing multi-agent systems, each offering unique features and benefits.

Microsoft AutoGen

Microsoft introduced the AutoGen framework to simplify the development of multi-agent applications. AutoGen is designed to orchestrate large language model (LLM) agents effectively. It provides a multi-agent conversation framework as a high-level abstraction, making it easier for next-generation LLM applications with multi-agent collaborations.
  • Simplified orchestration: AutoGen simplifies the process of managing workflows involving multiple agents.
  • High-level abstraction: It offers a structured approach to manage agent interactions and workflows.
  • Open source: It allows developers to customize and extend its capabilities to fit specific application needs.

The CrewAI framework

The CrewAI framework leverages the principles of teamwork, where:
  • Agents are initialized with specific attributes and capabilities.
  • Tasks have detailed descriptions of objectives and expected outcomes.
  • Tools provide agents with the ability to perform various actions effectively.
  • Processes dictate the strategic workflow, guiding how the crew approaches and completes tasks.

LangGraph

LangGraph employs a "divide-and-conquer" strategy for multi-agent collaboration. This strategy creates specialized agents for each task or domain and routes tasks to the appropriate "expert." This approach ensures that complex tasks are managed effectively, overcoming the limitations of a single agent, even powerful models like GPT-4.
LangGraph visualizes agent interactions and workflows, making it easier to optimize processes and identify improvements. This makes it an ideal framework for developing robust multi-agent systems that can efficiently tackle complex, multi-faceted tasks.
Having explored the frameworks that facilitate multi-agent collaborations, the next section will focus on integrating AutoGen with MongoDB. This integration promises to enhance the capabilities of multi-agent systems by leveraging MongoDB's vector store, NoSQL capabilities, scalability, flexibility, and real-time data handling, making it an ideal choice for supporting multi-agent frameworks.

Why AutoGen and MongoDB? 

AutoGen is an open-source framework designed to simplify the creation and management of AI agents, enabling them to collaborate effectively on complex tasks. By streamlining workflows, AutoGen optimizes the development of advanced LLM applications, integrating toolsets and automating code execution within its architecture.
  • One of AutoGen’s core strengths lies in its flexible conversation structures, supporting a variety of interaction modes such as two-agent dialogues, sequential chats, and group discussions. This adaptability allows developers to design agent interactions that fit the unique requirements of different tasks, providing customizable communication flows for more efficient task execution.
  • A key feature of AutoGen is its human-in-the-loop capability, which allows for real-time human oversight and intervention. This approach enhances decision-making, improves system accuracy, and increases the adaptability of the framework to handle evolving challenges, ensuring more reliable outcomes.
In multi-agent systems, MongoDB stands out as a powerful data management solution. Atlas Vector Search is particularly suited for the data-heavy demands of AI-driven environments. MongoDB allows vector embeddings to be stored alongside metadata and source data, with automatic synchronization to the vector index, ensuring the database remains up-to-date with minimal effort.
  • MongoDB’s Atlas Vector Search enables seamless querying of both vector data and traditional data through the MongoDB Query API, offering a unified and efficient querying experience. Its hybrid search capabilities combine traditional keyword searches with advanced semantic vector searches, delivering more contextually accurate results. This dual approach ensures that searches are not only relevant but also comprehensive, making it ideal for complex data environments.
  • The semantic caching layer of MongoDB further enhances performance, particularly in RAG applications. By caching query results based on their semantic meaning, MongoDB reduces redundant computations, speeding up response times while providing more relevant, context-aware interactions.
  • Additionally, MongoDB’s fully managed Atlas platform eliminates the need for manual infrastructure management, allowing developers to focus on building applications. Its dedicated search node infrastructure enhances resource efficiency, boosts performance, and ensures high availability, making MongoDB a scalable and reliable solution for handling the complex needs of multi-agent systems.
With these capabilities, MongoDB is an excellent choice for supporting the data-intensive demands of AI-powered, multi-agent systems, ensuring high performance, scalability, and relevance in complex applications.
AMP stack AutoGen MongoDB Python

Implementation guide: AutoGen MongoDB integration 

In this section, we'll explore how to integrate AutoGen with MongoDB to construct a powerful retrieval-augmented generation system using two distinct agents. 
We will guide you through setting up the necessary environment, configuring the agents, and illustrating how a question is processed by the retrieval agent, which fetches information from the MongoDB vector store. 
This data is then used to provide an augmented answer to the user via the user proxy agent. Here's a step-by-step explanation of the setup and implementation process:

Step 1: Installation and environment setup

Before coding, it is essential to set up the environment with all necessary dependencies. This involves creating a Conda environment and installing the required libraries.
1. Set up Conda environment:
Begin by creating a new Conda environment specifically for this project. This ensures a clean and isolated workspace.
Python 3.12: Ensure you have the correct Python version, as it supports the features needed for our implementation.
2. Install required libraries: Next, install the necessary libraries, including autogen for agent implementation and pymongo for MongoDB interaction.
  • pyautogen: This library provides the tools needed to create and manage agents within our framework.
  • pymongo: Essential for connecting and interacting with MongoDB databases.
  • Sentence_transformers: This package is crucial for MongoDB's vector usage, enabling efficient search and retrieval.
3. Install additional dependencies: Install additional packages required by AutoGen for enhanced functionality and compatibility.
  • ipython: Provides an interactive Python environment, facilitating testing and debugging
  • markdownify: Converts HTML content into Markdown; useful for processing documents
  • pypdf: Enables PDF document handling, which is crucial for retrieving text from various file formats
  • chromadb: Needed package for AutoGen dependency

Step 2: Multi-agent implementation

With the environment prepared, we import the necessary libraries and modules for our implementation. The autogen package is central to this setup, alongside specific agents for retrieval tasks. Using environment variables, we also handle sensitive information like API keys and MongoDB connection strings.
Note: Follow MongoDB’s steps to get the connection string from the Atlas UI. Securely store the URI within your development environment after setting up the database and obtaining the Atlas cluster connection URI.
Configuring AutoGen and MongoDB Next, we configure the model and MongoDB, ensuring secure access and compatibility with our vector database.
  • Autogen config list: We define the model to be used, specifying gpt-3.5-turbo-0125 with its API key. This configuration ensures that at least one model is set up for agent interaction.
  • MongoDB connection: The MongoDB URI is retrieved from environment variables, securing access to the database.
  • File formats: Accepted file formats for document retrieval are printed to confirm compatibility with the vector database.

Step 3: Creating the agents

The RetrieveAssistantAgent is initialized as an "assistant," acting as the primary interface to assist users with information retrieval.
  • Assistant agent: This agent is configured to interact with users, utilizing the specified model configuration.
The RetrieveUserProxyAgent is configured to facilitate communication between the user and the assistant. This agent is named MongoRAGagent and operates autonomously without requiring human input.
  • Human input mode: This is set to "NEVER," allowing the agent to function independently.
  • Vector database configuration: MongoDB settings, including connection string, database name, collection name, and index management, are defined. Wait times for index readiness are configured to optimize retrieval performance.
  • Document ingestion: Paths to documents are specified, with custom text types and chunk token sizes ensuring efficient processing.

Step 4: Initiating and managing conversations

The final step involves initiating and managing the conversation flow between the agents and the user.
  • Reset the assistant: Before starting a new conversation, the assistant is reset to clear any previous context and ensure accurate responses.
  • Problem statement: A code problem is defined — “How does the MAAP framework handle data ingestion?”
  • Initiate chat: The ragproxyagent generates a prompt and engages the assistant. The conversation continues until a termination condition is met, such as the absence of code blocks or user exit.
The results of the operations are as follows:

Conclusion

The integration of AutoGen with MongoDB enables the creation of advanced multi-agent systems by combining flexible agent orchestration with powerful data management and vector search capabilities. Developers can create sophisticated, scalable, and efficient agentic AI solutions by leveraging AutoGen's flexible agent orchestration capabilities and MongoDB's robust data management features.
This powerful combination allows for:
  • Enhanced collaboration among AI agents, mimicking high-performing human teams.
  • Efficient handling of complex, multi-faceted tasks through specialized agent roles.
  • Efficient retrieval and utilization of relevant information via MongoDB's vector search capabilities.
  • Improved context awareness and response relevance in AI interactions.
As the agentic AI space continues to evolve, frameworks like AutoGen, coupled with MongoDB's advanced data storage and retrieval systems, enable the development of more intelligent, adaptable, and capable multi-agent systems. This integration empowers developers to build AI solutions that can tackle increasingly complex challenges across various domains.
Following this implementation guide, you can integrate these tools to build intelligent agents capable of handling intricate tasks. All code presented in this article is available in this GitHub repository.

Frequently asked questions (FAQ)

1. What is the main benefit of integrating AutoGen with MongoDB?
The integration combines AutoGen’s multi-agent orchestration with MongoDB’s powerful data management and vector search capabilities. This enhances the performance of retrieval-augmented generation (RAG) systems by enabling agents to efficiently retrieve and process large amounts of data in real-time, improving decision-making and task execution.
2. How does MongoDB’s Atlas Vector Search enhance agent performance?
MongoDB’s Atlas Vector Search enables agents to perform both traditional keyword-based searches and semantic vector searches, ensuring more contextually accurate and relevant results. This dual-search capability allows agents to better handle complex queries, making interactions more efficient and effective.
3. Where can I find the official documentation for AutoGen and MongoDB integration?
You can find the official AutoGen documentation on Microsoft’s GitHub page
4. Where can I learn more about MongoDB Atlas and its vector search capabilities?
For detailed information about MongoDB Atlas and its vector search features, you can visit the official MongoDB documentation, which covers its powerful data management tools and hybrid search functionalities.
5. What types of applications can benefit from the AutoGen and MongoDB integration?
This integration can benefit applications that require data processing automation, retrieval-augmented generation, and multi-agent collaboration, such as AI-driven customer support systems, research assistants, and intelligent data analysis platforms. The framework is particularly suited for environments with high data demands and the need for real-time decision-making.
Top Comments in Forums
There are no comments on this article yet.
Start the Conversation

Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial

How to Use Custom Archival Rules and Partitioning on MongoDB Atlas Online Archive


May 31, 2023 | 5 min read
Tutorial

Efficient Sync Solutions: Cluster-to-Cluster Sync and Live Migration to Atlas


May 10, 2024 | 5 min read
Quickstart

Quick Start: Getting Started With MongoDB Atlas and Python


Apr 10, 2024 | 4 min read
Tutorial

Streaming Data from MongoDB to BigQuery Using Confluent Connectors


Jul 11, 2023 | 4 min read
Table of Contents