📘 Introduction

Welcome back to another hands-on OpenAI Agents tutorial! 🚀 In this guide, we’ll show you step-by-step how to add Function Tools to your AI Agent using the OpenAI Agents SDK.

By the end of this tutorial, you’ll know how to extend your agent’s abilities by equipping it with custom Python functions — so your assistant can do things, not just talk about things.

💡 What are Function Tools?

Function Tools let you connect Python functions directly to your AI agent. The SDK automatically sets them up as tools:

  • ✅ Tool name comes from your function name (or you can override it).
  • ✅ Description is extracted from the function’s docstring.
  • ✅ Schema for inputs is auto-generated from the function’s arguments.
  • ✅ Argument descriptions come from the docstring too.
💡
This means you can quickly transform any Python function into a tool your AI agent can call — whether it’s fetching weather data, reading files, or greeting a user.

✅ Prerequisites

Before starting, make sure you have:
🐍☑️ Python installed
📦☑️ Pip installed
🌐☑️ A virtual environment (venv) created
🔑☑️ An OpenAI API key generated (get one from OpenAI)
🔐☑️ OpenAI API key set as an environment variable (OPENAI_API_KEY="your_api_key_here")

📦1️⃣ Install Libraries

Activate your virtual environment and install the OpenAI Agents SDK:

pip install openai-agents

📥2️⃣ Import Libraries

Import the required modules into your Python script:

from agents import Agent, function_tool, Runner

⚙️3️⃣ Define your Function Tool

Let’s add a simple function that greets the user by name.

By decorating it with @function_tool, the SDK will automatically turn it into an AI-usable tool:

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