📘 Introduction

Welcome to this hands-on OpenAI Agents tutorial! In this guide, we’ll build a simple but powerful multi-agent system— a coordinated group of small AI agents that work together to handle different tasks. Our system will include one agent for travel suggestions, another for weather updates, and a triage agent that decides which one should respond.

You’ll also learn how to connect your system to an MCP tool, giving it access to hosted features like greeting users. By the end, you’ll have a fully functional multi-agent setup that can greet users, tell the weather, and offer travel tips — all powered by the OpenAI Agents SDK.

✅ Prerequisites

Before starting, make sure you have the following:

🐍☑️ Python installed
📦☑️ Pip installed
🌐☑️ A virtual environment (venv) created and activated
🔑☑️ An OpenAI API key generated (get one from OpenAI)
🔐☑️ OpenAI API key set as environment variable OPENAI_API_KEY

📦1️⃣ Install Libraries

Install the following Python packages using pip:

pip install openai-agents

📥2️⃣ Import Libraries

Start by importing the required Python modules:

from agents import Agent, function_tool, HostedMCPTool, Runner

⚙️3️⃣ Define a Python Tool

We’ll create a small tool to fetch weather information (mocked for this example):

@function_tool
def get_weather(city: str) -> str:
    return f"The weather in {city} is sunny with a pleasant breeze."

🔗4️⃣ Configure the Hosted MCP Tool

Now we connect to the Deep Learning Nerds MCP server, which we’ll use to greet users.

mcp = HostedMCPTool(tool_config={
    "type": "mcp",
    "server_label": "dlnerds",
    "server_url": "https://mcp-dlnerds.fastmcp.app/mcp",
    "allowed_tools": ["greet_user"],
    "require_approval": "never"
})

🤖5️⃣ Create Sub-Agents

We’ll define two small agents: one for travel suggestions and another for weather updates.

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In