Open In Colab

Open In Colab

Multi-Agent Order Management System with MongoDB

This notebook implements a multi-agent system for managing product orders, inventory, and deliveries using:

Setting Up MongoDB Atlas

  1. Create a free MongoDB Atlas account at https://www.mongodb.com/cloud/atlas/register
  2. Create a new cluster (free tier is sufficient)
  3. Configure network access by adding your IP address
  4. Create a database user with read/write permissions
  5. Get your connection string from Atlas UI (Click “Connect” > “Connect your application”)
  6. Replace <password> in the connection string with your database user’s password
  7. Enable network access from your IP address in the Network Access settings

Security Considerations

When working with MongoDB Atlas:

Setup

First, let’s install required dependencies:

>>> !pip install smolagents pymongo litellm
Requirement already satisfied: smolagents in /usr/local/lib/python3.10/dist-packages (1.0.0)
Requirement already satisfied: pymongo in /usr/local/lib/python3.10/dist-packages (4.10.1)
Requirement already satisfied: litellm in /usr/local/lib/python3.10/dist-packages (1.57.0)
Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (from smolagents) (2.5.1+cu121)
Requirement already satisfied: torchaudio in /usr/local/lib/python3.10/dist-packages (from smolagents) (2.5.1+cu121)
Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (from smolagents) (0.20.1+cu121)
Requirement already satisfied: transformers>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from smolagents) (4.47.1)
Requirement already satisfied: requests>=2.32.3 in /usr/local/lib/python3.10/dist-packages (from smolagents) (2.32.3)
Requirement already satisfied: rich>=13.9.4 in /usr/local/lib/python3.10/dist-packages (from smolagents) (13.9.4)
Requirement already satisfied: pandas>=2.2.3 in /usr/local/lib/python3.10/dist-packages (from smolagents) (2.2.3)
Requirement already satisfied: jinja2>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from smolagents) (3.1.4)
Requirement already satisfied: pillow>=11.0.0 in /usr/local/lib/python3.10/dist-packages (from smolagents) (11.0.0)
Requirement already satisfied: markdownify>=0.14.1 in /usr/local/lib/python3.10/dist-packages (from smolagents) (0.14.1)
Requirement already satisfied: gradio>=5.8.0 in /usr/local/lib/python3.10/dist-packages (from smolagents) (5.9.1)
Requirement already satisfied: duckduckgo-search>=6.3.7 in /usr/local/lib/python3.10/dist-packages (from smolagents) (7.2.0)
Requirement already satisfied: python-dotenv>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from smolagents) (1.0.1)
Requirement already satisfied: e2b-code-interpreter>=1.0.3 in /usr/local/lib/python3.10/dist-packages (from smolagents) (1.0.3)
Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in /usr/local/lib/python3.10/dist-packages (from pymongo) (2.7.0)
Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from litellm) (3.11.10)
Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from litellm) (8.1.7)
Requirement already satisfied: httpx<0.28.0,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from litellm) (0.27.2)
Requirement already satisfied: importlib-metadata>=6.8.0 in /usr/local/lib/python3.10/dist-packages (from litellm) (8.5.0)
Requirement already satisfied: jsonschema<5.0.0,>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from litellm) (4.23.0)
Requirement already satisfied: openai>=1.55.3 in /usr/local/lib/python3.10/dist-packages (from litellm) (1.57.4)
Requirement already satisfied: pydantic<3.0.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from litellm) (2.10.3)
Requirement already satisfied: tiktoken>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from litellm) (0.8.0)
Requirement already satisfied: tokenizers in /usr/local/lib/python3.10/dist-packages (from litellm) (0.21.0)
Requirement already satisfied: primp>=0.9.3 in /usr/local/lib/python3.10/dist-packages (from duckduckgo-search>=6.3.7->smolagents) (0.9.3)
Requirement already satisfied: lxml>=5.3.0 in /usr/local/lib/python3.10/dist-packages (from duckduckgo-search>=6.3.7->smolagents) (5.3.0)
Requirement already satisfied: attrs>=21.3.0 in /usr/local/lib/python3.10/dist-packages (from e2b-code-interpreter>=1.0.3->smolagents) (24.3.0)
Requirement already satisfied: e2b<2.0.0,>=1.0.4 in /usr/local/lib/python3.10/dist-packages (from e2b-code-interpreter>=1.0.3->smolagents) (1.0.5)
Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (23.2.1)
Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (3.7.1)
Requirement already satisfied: fastapi<1.0,>=0.115.2 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.115.6)
Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.5.0)
Requirement already satisfied: gradio-client==1.5.2 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (1.5.2)
Requirement already satisfied: huggingface-hub>=0.25.1 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.27.0)
Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (2.1.5)
Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (1.26.4)
Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (3.10.12)
Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (24.2)
Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.25.1)
Requirement already satisfied: python-multipart>=0.0.18 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.0.20)
Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (6.0.2)
Requirement already satisfied: ruff>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.8.6)
Requirement already satisfied: safehttpx<0.2.0,>=0.1.6 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.1.6)
Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (2.10.0)
Requirement already satisfied: starlette<1.0,>=0.40.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.41.3)
Requirement already satisfied: tomlkit<0.14.0,>=0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.13.2)
Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.15.1)
Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (4.12.2)
Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio>=5.8.0->smolagents) (0.34.0)
Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.5.2->gradio>=5.8.0->smolagents) (2024.10.0)
Requirement already satisfied: websockets<15.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.5.2->gradio>=5.8.0->smolagents) (14.1)
Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<0.28.0,>=0.23.0->litellm) (2024.12.14)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx<0.28.0,>=0.23.0->litellm) (1.0.7)
Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx<0.28.0,>=0.23.0->litellm) (3.10)
Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx<0.28.0,>=0.23.0->litellm) (1.3.1)
Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx<0.28.0,>=0.23.0->litellm) (0.14.0)
Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.10/dist-packages (from importlib-metadata>=6.8.0->litellm) (3.21.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema<5.0.0,>=4.22.0->litellm) (2024.10.1)
Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema<5.0.0,>=4.22.0->litellm) (0.35.1)
Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema<5.0.0,>=4.22.0->litellm) (0.22.3)
Requirement already satisfied: beautifulsoup4<5,>=4.9 in /usr/local/lib/python3.10/dist-packages (from markdownify>=0.14.1->smolagents) (4.12.3)
Requirement already satisfied: six<2,>=1.15 in /usr/local/lib/python3.10/dist-packages (from markdownify>=0.14.1->smolagents) (1.17.0)
Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.55.3->litellm) (1.9.0)
Requirement already satisfied: jiter<1,>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.55.3->litellm) (0.8.2)
Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai>=1.55.3->litellm) (4.67.1)
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas>=2.2.3->smolagents) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=2.2.3->smolagents) (2024.2)
Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dist-packages (from pandas>=2.2.3->smolagents) (2024.2)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3.0.0,>=2.0.0->litellm) (0.7.0)
Requirement already satisfied: pydantic-core==2.27.1 in /usr/local/lib/python3.10/dist-packages (from pydantic<3.0.0,>=2.0.0->litellm) (2.27.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.32.3->smolagents) (3.4.0)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.32.3->smolagents) (2.2.3)
Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=13.9.4->smolagents) (3.0.0)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=13.9.4->smolagents) (2.18.0)
Requirement already satisfied: regex>=2022.1.18 in /usr/local/lib/python3.10/dist-packages (from tiktoken>=0.7.0->litellm) (2024.11.6)
Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers>=4.0.0->smolagents) (3.16.1)
Requirement already satisfied: safetensors>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from transformers>=4.0.0->smolagents) (0.4.5)
Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (2.4.4)
Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (1.3.2)
Requirement already satisfied: async-timeout<6.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (4.0.3)
Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (1.5.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (6.1.0)
Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (0.2.1)
Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->litellm) (1.18.3)
Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch->smolagents) (3.4.2)
Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.10/dist-packages (from torch->smolagents) (1.13.1)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy==1.13.1->torch->smolagents) (1.3.0)
Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5.0,>=3.0->gradio>=5.8.0->smolagents) (1.2.2)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4<5,>=4.9->markdownify>=0.14.1->smolagents) (2.6)
Requirement already satisfied: protobuf<6.0.0,>=3.20.0 in /usr/local/lib/python3.10/dist-packages (from e2b<2.0.0,>=1.0.4->e2b-code-interpreter>=1.0.3->smolagents) (4.25.5)
Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=13.9.4->smolagents) (0.1.2)
Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio>=5.8.0->smolagents) (1.5.4)

Import Dependencies

Set in your secrets the MONGODB_URI and DEEPSEEK_API_KEY from https://www.deepseek.com/ (or any other LLM provider)

Import all required libraries and setup the LLM model:

from smolagents.agents import ToolCallingAgent
from smolagents import tool, LiteLLMModel, ManagedAgent, CodeAgent
from pymongo import MongoClient
from datetime import datetime
from google.colab import userdata
from typing import List, Dict, Optional

# Initialize LLM model
MODEL_ID = "deepseek/deepseek-chat"
MONGODB_URI = userdata.get("MONGO_URI")
DEEPSEEK_API_KEY = userdata.get("DEEPSEEK_API_KEY")

Database Connection Class

Create a MongoDB connection manager:

mongoclient = MongoClient(MONGODB_URI, appname="devrel.showcase.multi-smolagents")
db = mongoclient.warehouse

Agent Tools Defenitions

Our system implements three core tools for warehouse management:

Workflow:

Inventory Management Tools:
+-------------------+-------------------+
| Tool              | Description       |
+-------------------+-------------------+
| check_stock       | Queries stock     |
|                   | levels            |
+-------------------+-------------------+
| update_stock      | Adjusts inventory |
|                   | quantities        |
+-------------------+-------------------+

Order Management Tools:
+-------------------+-------------------+
| Tool              | Description       |
+-------------------+-------------------+
| create_order      | Creates new order |
|                   | document          |
+-------------------+-------------------+

Delivery Management Tools:
+-------------------+-------------------+
| Tool              | Description       |
+-------------------+-------------------+
| update_delivery   | Updates delivery  |
| _status           | status            |
+-------------------+-------------------+

Decision Flow:
+-------------------+-------------------+
| Step              | Action            |
+-------------------+-------------------+
| 1. Create Order   | Uses `create_order`|
|                   | tool to create    |
|                   | order document    |
+-------------------+-------------------+
| 2. Update Stock   | Uses `update_stock`|
|                   | tool to adjust    |
|                   | inventory         |
+-------------------+-------------------+
| 3. Update Delivery| Uses `update_delivery`|
| Status            | _status tool to   |
|                   | set delivery      |
|                   | status to         |
|                   | `in_transit`      |
+-------------------+-------------------+

Define tools for each agent type:

@tool
def check_stock(product_id: str) -> Dict:
    """Query product stock level.

    Args:
        product_id: Product identifier

    Returns:
        Dict containing product details and quantity
    """
    return db.products.find_one({"_id": product_id})


@tool
def update_stock(product_id: str, quantity: int) -> bool:
    """Update product stock quantity.

    Args:
        product_id: Product identifier
        quantity: Amount to decrease from stock

    Returns:
        bool: Success status
    """
    result = db.products.update_one({"_id": product_id}, {"$inc": {"quantity": -quantity}})
    return result.modified_count > 0
@tool
def create_order(products: any, address: str) -> str:
    """Create new order for all provided products.

    Args:
        products: List of products with quantities
        address: Delivery address

    Returns:
        str: Order ID message
    """
    order = {"products": products, "status": "pending", "delivery_address": address, "created_at": datetime.now()}
    result = db.orders.insert_one(order)
    return f"Successfully ordered : {str(result.inserted_id)}"
from bson.objectid import ObjectId


@tool
def update_delivery_status(order_id: str, status: str) -> bool:
    """Update order delivery status to in_transit once a pending order is provided

    Args:
        order_id: Order identifier
        status: New delivery status is being set to in_transit or delivered

    Returns:
        bool: Success status
    """
    if status not in ["pending", "in_transit", "delivered", "cancelled"]:
        raise ValueError("Invalid delivery status")

    result = db.orders.update_one({"_id": ObjectId(order_id), "status": "pending"}, {"$set": {"status": status}})
    return result.modified_count > 0

Main Order Management System

This class implements a multi-agent architecture for order processing with the following components:

The system follows this process flow:

  1. Create order documents for customer requests
  2. Verify and update product inventory levels
  3. Initialize delivery tracking status
  4. Coordinate agent interactions through the manager

Key Features:

Define the main system class that orchestrates all agents:

class OrderManagementSystem:
    """Multi-agent order management system"""

    def __init__(self, model_id: str = MODEL_ID):
        self.model = LiteLLMModel(model_id=model_id, api_key=DEEPSEEK_API_KEY)

        # Create agents
        self.inventory_agent = ToolCallingAgent(tools=[check_stock, update_stock], model=self.model, max_iterations=10)

        self.order_agent = ToolCallingAgent(tools=[create_order], model=self.model, max_iterations=10)

        self.delivery_agent = ToolCallingAgent(tools=[update_delivery_status], model=self.model, max_iterations=10)

        # Create managed agents
        self.managed_agents = [
            ManagedAgent(self.inventory_agent, "inventory", "Manages product inventory"),
            ManagedAgent(self.order_agent, "orders", "Handles order creation"),
            ManagedAgent(self.delivery_agent, "delivery", "Manages delivery status"),
        ]

        # Create manager agent
        self.manager = CodeAgent(
            tools=[],
            system_prompt="""For each order:
            1. Create the order document
            2. Update the inventory
            3. Set deliviery status to in_transit

            Use relevant agents:  {{managed_agents_descriptions}}  and you can use {{authorized_imports}}
            """,
            model=self.model,
            managed_agents=self.managed_agents,
            additional_authorized_imports=["time", "json"],
        )

    def process_order(self, orders: List[Dict]) -> str:
        """Process a set of orders.

        Args:
            orders: List of orders each has address and products

        Returns:
            str: Processing result
        """
        return self.manager.run(
            f"Process the following  {orders} as well as substract the ordered items from inventory."
            f"to be delivered to relevant addresses"
        )

Adding Sample Data

To test our order management system, we need to populate the MongoDB database with sample product data. The following section shows how to add test products with their prices and quantities. You can modify the product details or add more items by following the same structure. Each product has a unique ID, name, price, and initial stock quantity.

The sample data provides a representative mix of electronics products with varying price points and stock levels to demonstrate inventory tracking.

To test the system, you might want to add some sample products to MongoDB:

>>> def add_sample_products():
...     db.products.delete_many({})
...     sample_products = [
...         {"_id": "prod1", "name": "Laptop", "price": 999.99, "quantity": 10},
...         {"_id": "prod2", "name": "Smartphone", "price": 599.99, "quantity": 15},
...         {"_id": "prod3", "name": "Headphones", "price": 99.99, "quantity": 30},
...     ]

...     db.products.insert_many(sample_products)
...     print("Sample products added successfully!")


>>> # Uncomment to add sample products
>>> add_sample_products()
Sample products added successfully!

Testing the System

Here’s a markdown description of the test data approach:

Testing Strategy Overview:

  1. We test with two different order scenarios:

Test Data Design:

Alternative Test Examples:

The test demonstrates:

Let’s test our system with a sample order:

>>> # Initialize system
>>> system = OrderManagementSystem()

>>> # Create test orders
>>> test_orders = [
...     {
...         "products": [{"product_id": "prod1", "quantity": 2}, {"product_id": "prod2", "quantity": 1}],
...         "address": "123 Main St",
...     },
...     {"products": [{"product_id": "prod3", "quantity": 3}], "address": "456 Elm St"},
... ]

>>> # Process order
>>> result = system.process_order(orders=test_orders)

>>> print("Orders processing result:", result)
Orders processing result: Here’s the response to your request:

---

### **Processed Orders and Inventory Update**

1. **Orders Created**:
   - **Order 1**:
     - **Products**:
       - `prod1`: 2 units
       - `prod2`: 1 unit
     - **Delivery Address**: `123 Main St`
     - **Order ID**: `677b8a9ff033af3a53c9a75a`
   - **Order 2**:
     - **Products**:
       - `prod3`: 3 units
     - **Delivery Address**: `456 Elm St`
     - **Order ID**: `677b8aa3f033af3a53c9a75c`

2. **Inventory Updated**:
   - **`prod1` (Laptop)**:
     - Initial stock: 6 units
     - Subtracted: 2 units
     - New stock: 4 units
   - **`prod2` (Smartphone)**:
     - Initial stock: 13 units
     - Subtracted: 1 unit
     - New stock: 12 units
   - **`prod3` (Headphones)**:
     - Initial stock: 24 units
     - Subtracted: 3 units
     - New stock: 21 units

3. **Delivery Status**:
   - Both orders have been marked as **"in_transit"** and are ready for delivery.

---

### **Summary**:
- The orders have been successfully processed.
- The inventory has been updated to reflect the subtracted quantities.
- The delivery status for both orders is now **"in_transit"**.

Let me know if you need further assistance! 😊

System Output Analysis

The system successfully completes these key actions:

  1. Order Creation:

  2. Inventory Management:

  3. Delivery Status:

  4. Data Consistency:

When running the system, you might notice the agent attempting to interpret text output as Python code. This is an expected behavior of the CodeAgent as it tries to understand and process responses. After several attempts (max_iterations=10), it will stop if unsuccessful.

Example agent behavior:

  1. Receives text output from order creation
  2. Attempts to parse it as code
  3. Retries with different interpretations
  4. Eventually completes the workflow

The multi-agent system demonstrates resilient operation through its error handling and self-correction mechanisms. While initial attempts may produce error logs, the agent successfully adapts through iterations. Most importantly, the final state shows both successful order processing and accurate stock level updates, maintaining data consistency despite any intermediate errors.

This behavior is by design and doesn’t affect the system’s core functionality. The actual order processing, inventory updates, and delivery status changes are completed successfully through the MongoDB operations.

Conclusions

In this notebook, we have successfully implemented a multi-agent order management system using smolagents and MongoDB. We defined various tools for managing inventory, creating orders, and updating delivery statuses. We also created a main system class to orchestrate these agents and tested the system with sample data and orders.

This approach demonstrates the power of combining agent-based systems with robust data persistence solutions like MongoDB to create scalable and efficient order management systems.

< > Update on GitHub