Creating Multi-Agent Chatbots with PIDANTIC AI, MCP, and Advanced Web Scraping
The integration of AI models in development projects is inherently complex. Existing frameworks like LANGRAF and PIDANTIC AI, while powerful, often present challenges due to their high code abstraction and commercial nature. Enter MCP (Multi-agent Control Protocol), which is gaining acceptance as an open standard that offers compelling advantages for developers.
MCP’s open standards facilitate API development for service providers, prevent developers from redundantly creating solutions, and allow the seamless integration of existing MCP services to enhance capabilities. This approach represents a fundamental shift in designing AI-driven applications and distributed systems by effectively separating models, context, and protocols.
DeepSeek V3: A Game-Changing AI Model
Recently, DeepSeek released an open-source model called DeepSeek V3, a large mixture of experts model with 671 billion parameters, of which 37 billion are activated per token. This revolutionary model took only two months to train and cost less than $6 million, positioning it as a viable competitor to ChatGPT and creating waves across the global AI community.
The full training of DeepSeek V3 required only 2.788 million GPU hours. At an estimated rental price of $2 per GPU hour for H800 GPUs, the total training cost amounted to approximately $5.576 million. This achievement challenges traditional AI business models and demonstrates the potential for high-performance AI to become a tool for inclusive innovation.
DeepSeek accomplished this by adopting a hybrid expert architecture that selectively activates only necessary “brain cells” rather than engaging all simultaneously. This design dramatically reduces computing resource requirements. The training used just 2,048 NVIDIA H800 GPUs along with internally developed tools for generating high-quality training data. The implementation of FP8 technology during training further reduced memory requirements to half of traditional FP16 technology while maintaining computing performance.
Building a Multi-Agent Chatbot
Creating a multi-agent chatbot involves several components working together through the Multi-agent Control Protocol. Here’s how to set up the environment:
1. Setting Up the Environment
Start by installing the necessary Python libraries that support the model. Import classes from MCP server studio to run the server as a subprocess and connect to it using studio transport. FastMCP simplifies building MCP servers with clean Python code for creating tools, exposing resources, and defining prompts.
2. Creating a Python Tool with FastMCP
Define a FastMCP-powered Python tool that can execute arbitrary Python code and generate data visualizations using Matplotlib. This tool includes a Python ripple class that runs code in a restricted environment and captures execution results. It provides two main functions:
- Python ripple: Executes Python code and returns its output
- Data visualization: Runs Python code, saves Matplotlib plots, and returns the image as a base64-encoded string
3. Setting Up a Web Search Tool
Configure a web search tool using XRAPI (formerly called Metaphor) within the MCP framework. This search engine allows users to search using complete sentences and natural language, simulating how people share and discuss links online.
The implementation includes:
- Loading environment variables and initializing FastMCP with metadata
- Configuring an XRAPI client using an API key
- Defining a default search configuration (typically allowing five results per search)
- Registering the main function as an MCP tool that asynchronously queries XRAPI
- Formatting search results with titles, URLs, publication dates, and summaries
4. Developing the AI Agent
Create an AI agent that leverages the DeepSeek chat model for processing requests while integrating two MCP servers:
- XRBotchSearch.PI for handling web searches using XRAPI
- Python tools.PI for providing Python-based utilities including data analysis and visualization
The agent is defined using agent.run MCP servers which connects to these servers and retries up to three times if necessary. The main function runs the MCP servers and executes multi-step tasks.
Chatbot Capabilities
The resulting chatbot demonstrates impressive capabilities, including:
- Searching for the latest news about artificial intelligence
- Creating data visualizations (such as bar charts showing population data for major cities)
- Finding and analyzing climate change data
- Performing complex multi-step tasks by coordinating between tools
This implementation showcases how organizations can create adaptive, scalable, and maintainable AI solutions by effectively leveraging MCP architecture to separate models, context, and protocols. The approach democratizes access to sophisticated AI capabilities, making them available to entrepreneurs and developers with limited resources.