Summary: A Multi-Agent System (MAS) is multiple AI agents collaborating toward a bigger goal, each with a specific role. As AI applications mature, we move from single models answering simple questions to teams of agents solving complex problems. This tutorial makes the idea concrete by building a travel planner as a team of four specialized agents rather than one agent doing everything.

The design — a travel agency of agents

Like a real travel agency where different experts handle different tasks, the system uses four agents in a pipeline:

  1. Travel Research Agent — explores the destination, finds attractions, hidden gems, local experiences, and travel tips.
  2. Activity Planning Agent — turns the research into daily activities, sightseeing, and food plans.
  3. Budget Agent — estimates flight, visa, hotel, transport, and activity costs against the client's budget.
  4. Final Travel Assistant — combines all three outputs into one personalized itinerary.

The Agent class

Rather than coding each agent separately, OOP gives a reusable blueprint. Each agent stores a name (identity) and a role (a system prompt telling the model how to behave), and a run method that sends a task to the model:

from openai import OpenAI

client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key="YOUR API KEY")

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 model receives the agent's role (system message) plus the task (user message) and returns its answer. The example connects through OpenRouter.ai as the model provider.

Creating the agents and the workflow

Each agent is instantiated from the blueprint with a focused role prompt (e.g. the Research Agent is told to "find popular attractions, find hidden gems, suggest local experiences"). User input — origin, destination, days, travelers, budget, interests — is collected and assembled into a single request.

The multi-agent workflow is a sequential pipeline: each agent completes one task and passes its result to the next.

research   = research_agent.run(user_request)   # 1. research the destination
activities = activity_agent.run(research)        # 2. plan activities from research
budget     = budget_agent.run(activities)        # 3. cost the activities
final_plan = final_agent.run(                     # 4. combine everything
    f"Research:\n{research}\n\nActivities:\n{activities}\n\nBudget:\n{budget}\n\nCreate final travel plan."
)

Running it prompts for input and produces a personalized day-by-day itinerary with visa info, flight estimates, food suggestions, and a budget table.

Why multi-agent over one agent

You could build this with a single agent doing everything. Splitting the work among specialized agents makes the system more organized, more efficient, and closer to how real-world teams solve problems — each agent focuses on one task and collaborates toward a better, more personalized result. The natural next step is to make these agents more powerful by adding memory, external tools, APIs, and real-time data.