Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Building Agents with OpenAI  Agents SDK

You're reading from   Building Agents with OpenAI Agents SDK Create practical AI agents and agentic systems through hands-on projects

Arrow left icon
Product type Paperback
Published in Oct 2025
Publisher Packt
ISBN-13 9781806112012
Length 276 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Henry Habib Henry Habib
Author Profile Icon Henry Habib
Henry Habib
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Part 1: AI Agents
2. Introduction to AI Agents FREE CHAPTER 3. Introduction to OpenAI Agents SDK 4. Environment Setup and Developing Your First Agent 5. Part 2: OpenAI Agents SDK
6. Agent Tools and MCPs 7. Memory and Knowledge 8. Multi-Agent Systems and Handoffs 9. Model and Context Management 10. Agent System Management 11. Part 3: Build AI Agents
12. Building AI Agents and Agentic Systems 13. Other Books You May Enjoy
14. Index

Using custom tools with Python functions

In this section, let’s explore how to define and configure custom tools using Python functions within OpenAI Agents SDK. As a reminder, tools are a core part of the agent’s capabilities as they enable the agent to go beyond its internal knowledge and perform tasks such as fetching data, processing user requests, or triggering actions. We’ll begin with simple tool definitions using the @function_tool decorator and then progress to more advanced capabilities, such as overriding tool parameters and using Pydantic models for complex input validation.

Defining a new tool

As we discussed in the previous chapter, OpenAI Agents SDK provides a @function_tool decorator that turns any Python function into a tool that can be called by an agent. For example, we will bring back the code that we wrote in the previous chapter that creates a simple tool and calls an agent with that tool:

# Required imports
import os
from dotenv...
lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Building Agents with OpenAI  Agents SDK
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon