Introduction
Multi-agent systems (MAS) for large language models (LLMs) represent a significant advancement in AI-driven problem-solving. Rather than operating in isolation, LLM agents collaborate, exchange information, and make dynamic decisions to achieve complex objectives efficiently.
From document analysis and automated research to content generation and customer support, LLM-based MAS revolutionizes workflows by offering scalability, adaptability, and efficiency. Their ability to interact and coordinate dynamically enables efficient collaboration across multiple AI-driven tasks, optimizing performance in real-world applications.
In this tutorial, we'll explore LLM multi-agent fundamentals, real-world applications, and guide you step-by-step in building your own intelligent agent system. We will be using CrewAI, an open source framework for orchestrating autonomous AI agents and we will power it with Cortecs LLM workers. Get ready to bring AI collaboration to life!
Table of Contents:
- Understanding Multi-Agent Systems
- Setting Up the Development Environment
- Adding Dynamic Provisioning to Your Example Crew
- Running Your Crew
- Conclusion
Understanding Multi-Agent Systems
What Are Multi-Agent Systems?
An LLM-based MAS consists of multiple AI agents that interact in a shared environment to process language tasks efficiently. These agents, powered by large language models, collaborate by exchanging information, analysing data, and generating responses.
Key Components of LLM Multi-Agent Systems
- LLM Agents – AI-driven entities that process and generate text based on specific roles and objectives.
- Environment – The digital space where agents operate, such as document repositories, chat interfaces, or APIs.
- Communication – How agents share insights, using structured prompts, shared memory, or message-passing frameworks.
- Decision-Making – The strategies agents use to determine responses, often involving chain-of-thought reasoning or reinforcement learning.
Benefits of LLM Multi-Agent Systems
- Scalability – Handles large-scale text processing tasks efficiently.
- Collaboration – Multiple agents can divide and refine tasks for better accuracy.
- Adaptability – Easily integrates into various workflows and industries.
- Efficiency – Automates complex workflows with minimal human intervention.
Applications of LLM Multi-Agent Systems
- Automated Research – Agents collaborate to summarize, fact-check, and analyse documents.
- Content Generation – Teams of AI writers draft, edit, and refine articles.
- Customer Support – AI agents handle inquiries, escalate issues, and personalize responses.
- Data Extraction & Analysis – AI parses structured and unstructured text for insights.
Understanding these fundamentals prepares us to implement an LLM-based MAS!
Setting Up the Development Environment
Let's install the required libraries for this example:
pip install crewai crewai-tools uv
We'll use crewai
and its extension crewai-tools
to orchestrate our agents, while the uv
package manager helps run our crews.
Once the libraries are installed, we will create an example crew with:
crewai create crew example_crew
When prompted for a hardware provider, we can select OpenAI from the listed models. Since Cortecs LLM workers are OpenAI-compatible, we'll use our Cortecs credentials. First, create an account on Cortecs.ai, then visit your profile page to generate access credentials.
export CORTECS_CLIENT_ID=<YOUR_CORTECS_CLIENT_ID>
export CORTECS_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
export OPENAI_API_KEY=<YOUR_CORTECS_API_KEY>
Next, select a model for your crew. We recommend using an 🔵 Instantly Provisioned model like cortecs/phi-4-FP8-Dynamic
. The openai/ prefix indicates we're using an OpenAI-compatible endpoint.
export MODEL=openai/cortecs/phi-4-FP8-Dynamic
Adding Dynamic Provisioning to Your Example Crew
Let's dynamically provision an LLM worker to power our crew.
We will navigate to example_crew/src/example_crew/crew.py
and modify the ExampleCrew class with these two key functions:
-
start_llm
- This function initializes the Cortecs client and starts an LLM Worker of the desired model. We'll add it to the ExampleCrew class's
__init__
function to ensure it runs when the crew starts.
- This function initializes the Cortecs client and starts an LLM Worker of the desired model. We'll add it to the ExampleCrew class's
-
stop_and_delete_llm()
- To maximize cost efficiency, this function shuts down our resources when the crew completes its execution. We'll decorate it with the
@after_kickoff
hook to ensure proper cleanup.
- To maximize cost efficiency, this function shuts down our resources when the crew completes its execution. We'll decorate it with the
Here's the modified ExampleCrew class implementation:
import os
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task, after_kickoff #Add after_kickoff import
from cortecs_py import Cortecs
@CrewBase
class ExampleCrew:
def __init__(self):
self.start_llm()
def start_llm(self):
self.cortecs_client = Cortecs()
self.model = os.environ["MODEL"].removeprefix("openai/")
print(f"Starting model {self.model}...")
self.instance = self.cortecs_client.ensure_instance(self.model)
os.environ["OPENAI_API_BASE"] = self.instance.base_url
@after_kickoff
def stop_and_delete_llm(self, result):
self.cortecs_client.stop(self.instance.instance_id)
self.cortecs_client.delete(self.instance.instance_id)
print(f"Model {self.model} stopped and deleted.")
#The rest of the ExampleCrew stays the same...
You can further customize your crew by modifying agents.yaml, tasks.yaml and crew.py, or by following additional examples in the crewai docs.
Before running our crew, we will add the cortecs-py dependency to our pyproject file in example_crew/pyproject.toml
dependencies = [
"crewai[tools]>=0.100.1,<1.0.0",
"cortecs-py>=0.1.0" #Add this line
]
Running Your Crew
To run our crew, we will first navigate to the project directory (example_crew/
) and install the dependencies by running:
crewai install
Then we can execute the crew with:
crewai run
You'll see that an LLM worker instance starts up. Once it's ready, the crew executes its task. Afterward, the instance automatically stops and gets deleted.
The generated report will look similar to this:
# Comprehensive Report on Advances in Large Language Model (LLM) Technologies
## 1. Advanced Fine-Tuning Techniques
By 2025, significant advancements in fine-tuning techniques have marked a turning point for Large Language Models (LLMs). These improvements include few-shot and zero-shot learning, enabling models to perform new tasks with minimal task-specific data. Few-shot learning takes advantage of a minimal number of examples, allowing the model to generalize well across similar tasks. Zero-shot learning, on the other hand, lets the model tackle tasks without any task-specific training data. These techniques reduce dependency on extensive labeled datasets and expedite adaptation to diverse applications, offering flexibility and efficiency.
## 2. Multi-Modal Capabilities
LLMs have evolved to incorporate multi-modal data, effectively integrating information from text, images, video, and audio. This enhancement broadens their application across various sectors. In healthcare, multi-modal LLMs facilitate complex case studies by correlating clinical text with imagery and patient history. In autonomous systems, they enhance decision-making by combining sensory data with textual inputs. This synergy results in richer, more contextual insights, enabling more comprehensive understanding and interaction within environments.
...
Conclusion
In this tutorial, we've explored how to build a multi-agent system using CrewAI and Cortecs LLM workers. We covered the fundamentals of LLM-based multi-agent systems, from understanding their key components to practical implementation. We've learned how to set up your development environment, dynamically provision LLM workers, and create a functional crew that can efficiently handle complex tasks.
To dive deeper into multi-agent systems, check out the CrewAI documentation and explore the Cortecs platform. Happy building! 🚀✨
Top comments (0)