Introduction to Multi-Agent AI Systems
In the rapidly evolving landscape of artificial intelligence, single-agent models have given way to sophisticated multi-agent systems that mimic human collaboration. These systems enable specialized AI entities to work together, dividing complex tasks into manageable parts and iteratively refining outputs. Recently, I developed such a system leveraging Microsoft's AutoGen, LangChain's robust tool ecosystem, and Hugging Face's vast repository of open-source large language models (LLMs). This setup demonstrates practical agentic AI workflows, where agents autonomously handle research, coding, execution, and validation—perfect for tasks like data analysis or software prototyping.
The motivation? Traditional LLMs excel at isolated tasks but falter in multi-step, interdependent workflows. By orchestrating agents with distinct roles, we achieve higher accuracy, error correction through peer review, and scalability. This project showcases a real-world example: analyzing the Titanic dataset to predict survival rates, involving web research, code generation, execution, and critique—all without human intervention.
Core Technology Stack
To bring this vision to life, I selected tools that complement each other's strengths:
- AutoGen: A framework from Microsoft for building conversational multi-agent applications. It handles agent orchestration, group chats, and dynamic interactions seamlessly. Check out the official repo here.
- LangChain: Provides modular components like chains, agents, and tools (e.g., search engines, code interpreters). Essential for equipping agents with external capabilities beyond pure generation. Explore it at LangChain's GitHub.
- Hugging Face: Hosts lightweight, efficient LLMs like Mistral, Qwen2.5-Coder, and Phi-3.5, runnable locally or via APIs, reducing costs and latency.
Additional dependencies include LiteLLM for unified LLM access, DuckDuckGoSearchRun for web queries, and PythonREPLTool for safe code execution. This stack ensures the system is flexible, deployable on consumer hardware, and extensible.
System Architecture Overview
The architecture revolves around four specialized agents forming a collaborative loop:
- Researcher Agent: Gathers domain knowledge via web searches, providing context for downstream tasks.
- Coder Agent: Generates Python code based on research and requirements, using a code-specialized LLM.
- Executor Agent: Runs the generated code in a sandboxed environment, capturing outputs and errors.
- Reviewer Agent: Critiques results for accuracy, suggests improvements, and approves or loops back for revisions.
These agents communicate via AutoGen's GroupChat mechanism, where a manager agent moderates turns. Tools are integrated using LangChain's create_react_agent pattern, allowing agents to decide when to use external functions. For LLMs, configurations point to Hugging Face models via Ollama or direct inference, with system prompts defining roles clearly.
Here's a simplified diagram in text form:
Task Input → Researcher (Search Tool) → Coder (Code Gen) → Executor (REPL Tool) → Reviewer (Critique)
↑_______________________________________________________________________|
Iterative Feedback Loop
This design promotes fault tolerance—if code fails, the reviewer flags it, triggering recoding.
Step-by-Step Implementation Guide
1. Environment Setup
Start with Python 3.10 or higher. Use Conda for dependency management:
conda create -n multiagent python=3.10
conda activate multiagent
Install packages:
pip install -U autogen-agentchat pyautogen langchain langchain-community langchain-core langchain-huggingface litellm duckduckgo-search
pip install ollama # For local HF model serving
Obtain a Hugging Face token for gated models (e.g., huggingface-cli login). Pull models like Qwen/Qwen2.5-Coder-7B-Instruct via Ollama:
ollama pull Qwen/Qwen2.5-Coder-7B-Instruct
ollama pull mistral-nemo
2. LLM Configuration
Define config_lists for agent-specific models. For example:
from autogen import AssistantAgent, UserProxyAgent
coder_config = {
"model": "Qwen/Qwen2.5-Coder-7B-Instruct",
"base_url": "http://localhost:11434/v1",
"api_key": "ollama", # Dummy for Ollama
}
researcher_config = {
"model": "mistral-nemo",
"base_url": "http://localhost:11434/v1",
"api_key": "ollama",
}
This allows mixing models optimized for different tasks—coder for programming, generalist for research/review.
3. Tool Integration with LangChain
Tools empower agents. Create LangChain agents with ReAct (Reasoning + Acting):
from langchain.agents import create_react_agent, AgentExecutor
from langchain.tools import DuckDuckGoSearchRun, PythonREPLTool
from langchain_huggingface import HuggingFaceEndpoint
# Search Tool
search_tool = DuckDuckGoSearchRun()
# Code Execution Tool (sandboxed)
executor_tool = PythonREPLTool()
# Bind to agents later
4. Agent Definition and Group Chat
Instantiate agents with roles:
researcher = AssistantAgent(
name="Researcher",
llm_config=researcher_config,
system_message="You are a researcher. Use search tools to find relevant info.",
tools=[search_tool]
)
coder = autogen.CoderAgent( # Specialized
name="Coder",
llm_config=coder_config,
system_message="Write clean, executable Python code."
)
executor = AssistantAgent(
name="Executor",
llm_config=researcher_config,
tools=[executor_tool]
)
reviewer = AssistantAgent(
name="Reviewer",
llm_config=researcher_config,
system_message="Critique code and outputs rigorously. Suggest fixes."
)
# Group Chat
manager = autogen.GroupChatManager(agents=[researcher, coder, executor, reviewer])
5. Orchestrating the Workflow
Kick off with a user proxy:
user_proxy = UserProxyAgent(name="User", human_input_mode="NEVER")
user_proxy.initiate_chat(
manager,
message="Analyze the Titanic dataset: predict survival rates using logistic regression. Provide insights."
)
The group chat handles sequencing dynamically.
Full code and notebooks are available in the project repository: https://github.com/pranav-manudhane/multi-agent-system.
Running and Testing the System
Execute via CLI:
python main.py --task "Perform exploratory data analysis on Iris dataset and visualize distributions."
Watch in real-time as:
- Researcher queries DuckDuckGo for dataset details.
- Coder drafts Pandas/Scikit-learn code.
- Executor runs it, outputs plots/errors.
- Reviewer validates (e.g., "Model accuracy 82%—good, but add cross-validation.") and iterates.
Sample output includes generated code like:
import pandas as pd
import seaborn as sns
from sklearn.linear_model import LogisticRegression
titanic = sns.load_dataset('titanic')
# ... preprocessing, model fitting, predictions
print(model.score(X_test, y_test))
This workflow completes complex tasks in minutes, far surpassing single-prompt chains.
Enhancements and Real-World Applications
To scale:
- Add memory with AutoGen's stateful chats.
- Integrate RAG via LangChain for proprietary data.
- Deploy on cloud with Ray/ Kubernetes for parallelism.
- Fine-tune HF models on domain data.
Applications span devops (CI/CD automation), research (lit review + hypothesis testing), and business (market analysis reports). For production, monitor costs—local Ollama keeps it free.
Potential pitfalls: Hallucinations (mitigated by tools/review), tool failures (add retries), and context limits (chunk long convos).
Conclusion
This multi-agent system bridges theory and practice in agentic AI, proving how AutoGen, LangChain, and Hugging Face enable emergent intelligence through collaboration. Fork the repo here, experiment with your tasks, and push agentic workflows forward. The future is multi-agent—start building today!
(Word count: ~1250)
<div style="text-align: center; margin-top: 2rem;"> <a href="https://www.marktechpost.com/2025/10/21/how-i-built-an-intelligent-multi-agent-systems-with-autogen-langchain-and-hugging-face-to-demonstrate-practical-agentic-ai-workflows/" target="_blank" rel="noopener noreferrer" class="view-full-resource-btn" style="display: inline-block; background-color: #f97316; color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: 600; transition: background-color 0.2s;">View Full Resource</a> </div>
Stay ahead of the AI curve
The most important updates, news, and content — delivered in one weekly newsletter.