Building a Multi-Agent System in Python

they are the talk of the town. We see them everywhere, even used for simple tasks on our phones. They are easy to use, fast, and very reliable, and they help us navigate everyday life. If you want a simple explanation of a scientific concept, you ask ChatGPT. You want a guide to your chosen child's meal plan, so you ask AI. Even the task of planning your perfect travel itinerary can be transferred to AI. And, that's exactly what we're going to do in this tutorial (stay tuned!).
We know about AI Agents, but what if we could build and deploy different AI Agents for different roles in a larger project? This is where the concept of a multi-agent system comes into play. As AI systems become more advanced, we are moving from single AI models that answer simple questions and perform specific tasks to systems where multiple AI agents work together to solve complex problems. A Multi-agent system (MAS) a concept where multiple AI agents work together to achieve a greater goal. Each of these has a specific role that leads to the final goal, and they accomplish it together.
A Multi-Agent Scheduling System
In this project, we will be developing a Multi-Agent Scheduling System. So, what we will have is that instead of just one AI Agent that will plan our trip, we will have a group of AI agents, each with a specific role, and they will work together to make a great travel plan for us!
We can think of the Multi-Agent Travel Planning System as a real travel agency. Instead of one person in charge of everything, different professionals will be in charge of different tasks according to their expertise and work together. In our AI Travel Planner, we will have the following agents:
- Tourism Research Agent: This agent will carry out research activities. It will explore the area where the client wants to go and find attractions, hidden places, local experiences, travel tips, etc. It will collect the basic information needed to plan the trip.
- Job Planning Agent: This agent will plan jobs based on the Research Agent's research. It will be the one that decides which place to visit, the time to visit, what activities to do, and how to plan the whole trip!
- Budget Agent: This agent is responsible for making a proper budget. It will analyze the plan shared by the Travel Agent and share expected costs, affordable options, money saving tips, and help customize the trip to the client's budget.
- Ultimate Travel Assistant: Finally, the ultimate travel assistant will combine the outputs of all three agents: research, activity plan, and budget, and create a simple personalized itinerary!
Here's what a typical workflow for every project would look like:

We will build this project in Python, using the PyCharm IDE. This is an intermediate level Python project that requires a basic understanding of AI Agents in Python, and some basic knowledge of Object-Oriented Programming, as we will be creating classes. If you are new to Python and Agentic AI, you can access my beginner-friendly Agentic AI tutorial from the following link:
A Beginner's Guide to Building an AI Agent in Python
If you want to learn about Python OOP, you can read the following articles where I created a coffee machine in Python, and then, in the next lesson, I used the concept of OOP to make the code better:
Using Coffee Machine in Python
Implementing the Coffee Machine Project in Python Using Object Oriented Programming
All these articles will give you a basic understanding of Python code, and will help you understand the code that comes under this exciting project. Let's start coding the project!
Creating a Project
The first thing is to create a project folder in PyCharm (or the IDE of your choice) and name the project “Multi-Agent System” (whatever you choose).

Installing and Importing Python Packages
Once the project folder is created, go ahead and create the “main.py” file where we will do the coding In Terminal, install OpenAI and import it into your code file.
pip install openai

from openai import OpenAI
Connecting Python with AI Modeling
In order for our program to communicate with OpenAI and process the code, we need to connect it to the AI environment. In our case, we will use OpenRouter.ai and add its URL. We'll also add an API key to our code, saving it to api_key flexible. This API key will give our program the necessary permission to use the AI models. We will create a client that will communicate with the AI model using the API key we created:
client = OpenAI(
base_url="
api_key="YOUR API KEY"
)
Once you have created an API key on OpenRouter.ai, do not share the key with anyone. Just add in the field “YOUR API KEY”.
Creating an Agent Class
Now comes the part of coding the AI agents. Since we are not creating one or two agents, we will not write the code directly. Instead, we will use the concept of OOP, and create a class (or blueprint in simple words) for the agent class, and then use this diagram to create each agent in advance. The agent will store a name that identifies the agent, and a role, which tells the AI how the agent should behave. In addition, we will also develop an application that will give our AI agents the ability to act, that is, to send tasks to the AI model.
class Agent:
def __init__(self, name, role):
self.name = name
self.role = role
def run(self, task):
print(f"{self.name} is working...")
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{
"role": "system",
"content": self.role
},
{
"role": "user",
"content": task
}
],
max_tokens=1200
)
return response.choices[0].message.content
The code above will send the following two items to the AI model (which we also specified):
- Job/role of relevant agent
- User message taken as user input (as you will see later)
We will get the AI Response returned from this code in the following code return response.choices[0].message.content. This return statement will output the response generated by the agent (if you find it difficult to understand this code, see my original AI Agent guide article linked at the beginning of this article).
Creating Agent Objects
Now that our agent class is created, we will use this program to create our AI agents. The following code uses the OOP concept to create agent objects, namely:
- Research agent
- Employment Agent
- Budget Agent
- The last agent
research_agent = Agent(
"Research Agent",
"""
You are an expert travel researcher.
Your job:
- Find popular attractions
- Find hidden gems
- Suggest local experiences
- Recommend best places
"""
)
activity_agent = Agent(
"Activity Planner Agent",
"""
You are a professional travel planner.
Your job:
- Create daily activities
- Plan sightseeing
- Recommend food experiences
- Organize activities logically
"""
)
budget_agent = Agent(
"Budget Agent",
"""
You are a travel budget expert.
Calculate:
- Estimated flight cost
- Visa requirements
- Visa fees if needed
- Hotel cost
- Food expenses
- Transport cost
- Activity costs
Create an approximate total trip budget.
Keep response short.
"""
)
final_agent = Agent(
"Final Travel Assistant",
"""
You are a professional travel planner.
Create the final itinerary.
Include:
1. Short trip overview
2. Visa information
3. Estimated flight cost
4. Day-wise plan
5. Food suggestions
6. Total estimated budget
Keep everything under 700 words.
"""
)
This code will create individual AI agents with specific roles as specified in the code. A role tells the AI model how it should behave and what task it should focus on.
User input
The next task is to get input from the user. We will ask the user the following questions:
- Where are they from?
- They also fly
- Number of days of travel
- Number of travelers
- Interests
#Get User Travel Details
starting_location = input(
"Where are you flying from? "
)
destination = input(
"Where do you want to travel? "
)
days = input(
"How many days is your trip? "
)
travelers = input(
"How many travelers? "
)
budget = input(
"What is your budget? (low/medium/high) "
)
interests = input(
"What are your interests? "
)
Creating a User Request
After collecting information from the user through input statements, we combine everything into a single notification and forward it to the AI agents.
# Create request for AI agents
user_request = f"""
Create a travel plan with these details:
Flying From:
{starting_location}
Destination:
{destination}
Trip Duration:
{days} days
Number of Travelers:
{travelers}
Budget Level:
{budget}
Interests:
{interests}
Include:
- Visa requirements
- Estimated flight cost
- Places to visit
- Activities
- Food recommendations
- Total estimated budget
"""
print("nCreating your AI travel plan...n")
While the AI is running in the background, we will print the statement “Creating your AI travel plan”, so that the user knows that the process is running and the agents have started working.
Multi-Agent Workflow
Now that we have created the user request, by providing all the information we have captured from the user, let's now get the workings of the multi-agent system. Each agent completes one task and passes its result to the next agent.
User flow data is first sent to the Research Agent. This agent asks an AI model to find the best places to visit, local information, and travel information. The result is kept in the study. The output of the survey becomes the input of the Work Agent. It turns travel information into daily activities, sightseeing plans, and dining ideas. The result is stored in the functions. Then comes the Budget Agent who receives scheduled activities and estimates the cost of flights, visas, hotels, transportation, etc. The result is stored in budget. The Final Travel Agent receives information from all previous agents and combines everything into one complete travel plan, which is then issued to the user.
#Multi-Agent Workflow
#Agent 1 researches destination
research = research_agent.run(
user_request
)
print("n--- Research Completed ---")
#Agent 2 creates activities
activities = activity_agent.run(
research
)
print("n--- Activities Planned ---")
#Agent 3 calculates budget
budget = budget_agent.run(
activities
)
print("n--- Budget Created ---")
#Agent 4 creates final itinerary
final_plan = final_agent.run(
f"""
Research:
{research}
Activities:
{activities}
Budget:
{budget}
Create final travel plan.
"""
)
print("n==========================")
print(" FINAL TRAVEL PLAN")
print("==========================n")
print(final_plan)
Using the Code
By running the code, you can see the program asking for user input. You can add your specific information, answer questions. It is based on these answers that a team of AI agents will create your itinerary.

"C:UsersMahnoor JavedPycharmProjectsMulti Agent System.venvScriptspython.exe" "C:UsersMahnoor JavedPycharmProjectsMulti Agent Systemmain.py"
Where are you flying from? islamabad
Where do you want to travel? istanbul
How many days is your trip? 3
How many travelers? 4
What is your budget? (low/medium/high) $4k
What are your interests? kid frinedly
Creating your AI travel plan...
Research Agent is working...
--- Research Completed ---
Activity Planner Agent is working...
--- Activities Planned ---
Budget Agent is working...
--- Budget Created ---
Final Travel Assistant is working...
==========================
FINAL TRAVEL PLAN
==========================
### 3-Day Family-Friendly Itinerary: Islamabad to Istanbul
---
#### Trip Overview
Discover Istanbul’s captivating blend of history, culture, and family-friendly fun on this 3-day trip from Islamabad. Explore iconic landmarks like Hagia Sophia and Topkapi Palace, dive into interactive experiences at Istanbul Aquarium and KidZania, and unwind in beautiful parks and bustling bazaars. This itinerary balances cultural discovery with engaging activities perfect for kids, ensuring memories for the entire family.
---
#### Visa Information
- **For Pakistani Citizens:** Turkish e-Visa required
- **Application:** Apply online before travel at [e-Visa Turkey official website]
- **Cost:** Approx. $50 per person
- **Processing time:** Usually 24-48 hours
- **Tip:** Carry a printout or e-copy of the e-Visa during travel.
---
#### Estimated Flight Cost
- **Route:** Islamabad (ISB) – Istanbul (IST) round-trip
- **Cost:** $350 - $450 per person in economy class
- **For 4 travelers:** Approx. $1,400 - $1,800 total
- **Tip:** Book 2-3 months in advance to secure better deals.
---
### Day-wise Itinerary
**Day 1: Historic and Iconic Sights**
- **Morning:**
- Arrive Istanbul, transfer and check-in at a family-friendly hotel near Sultanahmet.
- Visit **Hagia Sophia**, immersing in the grandeur of this iconic monument.
- Walk to **Topkapi Palace**, exploring expansive gardens and kid-friendly spaces.
- **Afternoon:**
- Relax and play at **Sultanahmet Square**; kids enjoy ample open space.
- Hop on the nostalgic **Sultanahmet tram** for a charming ride around the historic district.
- **Evening:**
- Enjoy a **Bosphorus dinner cruise** featuring family entertainment and kid activities alongside delicious Turkish cuisine.
---
**Day 2: Interactive Fun and Exploration**
- **Morning:**
- Visit **Istanbul Aquarium (Florya)** to see diverse marine life, touch pools, and themed zones.
- Lunch at aquarium’s family-friendly café or nearby **Forum Istanbul Mall**.
- **Afternoon:**
- Interact and play at **KidZania Istanbul** inside the mall where children role-play professions and learn through fun.
- Enjoy mall playgrounds and snack breaks.
- **Evening:**
- Try famous **Maraş dondurma** (Turkish ice cream) with entertaining vendor shows.
- Leisurely mall or park walk before returning to hotel.
---
**Day 3: Parks, Museums, Markets & Local Flavors**
- **Morning:**
- Picnic and playtime at **Gülhane Park** with pony rides for children.
- Explore the **Rahmi M. Koç Museum** featuring interactive exhibits including vehicles, toys, and a submarine.
- **Afternoon:**
- Short visit to the **Grand Bazaar** focusing on kid-friendly souvenir shops.
- Sample local street food: **simit** (sesame bagels) and **gözleme** (savory crepes).
- **Evening:**
- Dinner at **Çiya Sofrası** for mild traditional dishes or try **Saray Muhallebicisi** for authentic Turkish desserts like sütlaç (rice pudding).
---
### Food Suggestions
- **Çiya Sofrası (Kadıköy):** Authentic Turkish with kid-friendly options
- **Saray Muhallebicisi:** Traditional desserts perfect for family treats
- **Midpoint/Cookshop:** Casual dining with international and local menus suitable for children
- **Street Food:** Try simit, lahmacun (Turkish pizza), and borek pastries at local vendors
---
### Estimated Budget (4 Persons)
| Category | Estimated Cost (USD) |
|---------------------------|-------------------------------|
| Flights (Round-trip) | $1,400 - $1,800 |
| Visa Fees | $200 |
| Accommodation (3 nights) | $600 - $800 |
| Food | $300 - $400 |
| Transport (Istanbulkart, taxis) | $100 |
| Entrance Fees & Activities| $300 |
| Miscellaneous | $200 |
| **Total Estimate** | **~$3,100 - $3,800** |
*Note: Budget can vary depending on hotel choice and dining preferences.*
---
### Additional Tips
- Book tickets online in advance for popular attractions to skip queues.
- Purchase an **Istanbulkart** for convenient and discounted travel on public transport.
- Pack comfortable shoes and sun protection for children.
- Opt for accommodations with family amenities and close proximity to tram or metro stations in Sultanahmet or Beyoğlu districts.
- Many restaurants provide kids’ menus and high chairs—ask beforehand.
---
Would you like personalized hotel recommendations and help with booking flights? Also, I can assist you with local transport details or restaurant reservations. Just let me know!
Process finished with exit code 0
The above is the code release. You can see how the itinerary is customized for you!
The conclusion
In this project, we successfully used our knowledge of building AI agents in Python to create something that works and has real applications. Such are real-world problems: we already have a working system, but we need to improve it and make it work better, and this can be easily done by using some basic concepts.
We could build this trip planner using a single AI agent and ask it to handle everything. However, by building a multi-agent system, we divided the work into specialized agents, each focusing on one specific task. This approach makes the system more organized, efficient, and closer to how real-world teams solve problems. Instead of a single AI trying to do everything, multiple AI agents work together to create a better and more personalized user experience.
By adding memory, external tools, APIs, and real-time data, these agents can become even more powerful and solve complex real-world problems; project next time!



