OpenAI Agents SDK tutorial (Python): first agent, tools, handoffs, MCP
OpenAI Agents SDK tutorial for Python Checked against the official docs: Nov 4, 2026 The OpenAI Agents SDK ( openai-agents on PyPI) is OpenAI's open-source Python framework for building agents: a model with instructions, tools it can call, and the option to hand a conversation to another agent. This tutorial goes from an empty folder to an agent that uses your own Python functions, routes…
OpenAI's Agents SDK for Python provides a framework for building agents with models, instructions, tools, and the capability to pass conversations to other agents. This tutorial walks you through creating an agent that uses your own Python functions, routes questions between specialists, remembers earlier turns, and calls an MCP server.
To get started, ensure you have Python 3.10 or newer installed. Create a project folder with its own virtual environment to keep the SDK and its dependencies separate from your system Python. Install the openai-agents package using pip install openai-agents. Set the OPENAI_API_KEY environment variable in your terminal to authenticate with the OpenAI service.
The basic structure of an agent involves creating a model with instructions and tools. You can run the agent using the Runner.run() function in async code, which is suitable for web servers and running multiple agents simultaneously. Runner.run_sync() is an alternative for plain scripts, but it won't work inside an already running event loop.
Agents can utilize function tools, which are ordinary Python functions that the model can decide to call. These tools are defined using the @tool decorator from the agents.decorators module. The SDK also supports hosted tools like WebSearchTool() and FileSearchTool(), which you can add to the tools list in the same way.
One of the key features of the Agents SDK is the ability to hand off conversations between agents. This allows for more specialized responses to complex queries. Each specialist agent should have a handoff_description to indicate when to route the conversation.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to