Welcome back! In the last lesson, you learned how to manage multi-turn conversations with your agent, making it possible for your applications to remember and build on previous exchanges. This is a key feature for creating natural, interactive experiences. Now, you are ready to take the next step: extending your agent’s capabilities beyond just generating text.
In real-world applications, agents often need to do more than just talk — they might need to search the web, perform calculations, or interact with external systems. The OpenAI Agents SDK makes this possible by allowing you to add “tools” to your agents. Tools can be built-in (like web search) or custom Python functions that you define yourself. By the end of this lesson, you will know how to add both types of tools to your agent, making it much more powerful and useful.
The OpenAI Agents SDK comes with several built-in tools that you can add to your agent with just a few lines of code. One of the most useful is the WebSearchTool
, which allows your agent to search the web for up-to-date information. This is especially helpful when your agent needs to answer questions about recent events or look up facts that are not part of its training data.
Let’s look at a simple example. Suppose you want to create an agent that can answer questions by searching the web. You can do this by adding the WebSearchTool
to the tools
parameter of your agent:
With this setup, your agent can now use the web search tool whenever it needs to find information. This is a big step up from a basic text-only agent, as it can now provide answers based on the latest information available online.
While built-in tools are powerful, sometimes you need your agent to perform a specific task that is unique to your application. This is where custom function tools come in. The OpenAI Agents SDK allows you to turn any Python function into a tool that your agent can use by decorating it with @function_tool
.
To ensure the agent knows how to call your function tool correctly, you define the expected input parameters using a TypedDict class. TypedDicts specify the structure and types of the input arguments, making it clear to both the SDK and the agent what data is required. This explicit schema helps the agent construct valid calls to your function tool during its reasoning process.
For example, suppose you want your agent to calculate the number of years between two historical events. You can define a custom function tool like this:
Here, the Years
TypedDict defines that the function expects a dictionary with two integer fields: year1
and year2
. The @function_tool
decorator registers the function as a tool, and the docstring provides a human-readable description that the agent can use to decide when and how to use the tool. By using TypedDicts, you ensure that the agent understands the required input structure, which is essential for reliable and accurate tool usage.
Now that you have both a built-in tool (WebSearchTool
) and a custom function tool (calculate_years_between
), you can combine them in a single agent. This allows your agent to use both tools as needed to answer user questions.
Here’s how you can create an agent with multiple tools:
In this example, the agent is given clear instructions on how to use its tools: first, search the web to find the years of the events, and then use the calculation tool to find the difference. By listing both tools in the tools
parameter, you make them available for the agent to use during its reasoning process.
If you want to verify that the custom function tool you created is correctly set up for your agent to use, you can inspect the agent’s list of tools and print out details for each function tool. This is especially useful for checking that your tool’s name, description, and parameter schema are registered as expected.
To do this, you can iterate through the agent’s tools
list and print information only for tools that are instances of FunctionTool
(which includes your custom function tools, but not built-in tools like WebSearchTool
):
This will output details for each function tool, allowing you to confirm that your custom tool is properly registered and ready for the agent to use.
Once your agent has its tools, you can run it just like before. The difference is that now, the agent can decide when to use each tool to answer the user’s question. For example, if you ask, “How many years are there between Benjamin Franklin’s discovery of electricity and ChatGPT?”, the agent will first use the web search tool to find the years of each event, then use the calculation tool to compute the difference.
Here’s how you can run the agent and see the result:
By using the to_input_list()
method on the result, you can view a detailed, step-by-step breakdown of how the agent used its tools—including each tool invocation, the arguments passed, and the outputs returned. The output might look something like this:
This shows how the agent used both tools to answer the question, providing a clear and accurate response.
Integrating tools with different agentic systems can be difficult and time-consuming. Each platform often has its own way of defining and connecting tools, leading to duplicated work, inconsistent APIs, and maintenance headaches. As you add more tools or want to support multiple agent frameworks, these challenges multiply.
The Model Context Protocol (MCP) is a game changer. MCP is an open standard that lets you develop a tool once and make it available to any agentic system that supports the protocol. It standardizes how tools are described, discovered, and invoked, making integration much simpler and more reliable. With MCP, you can build tools that work across platforms, reduce integration effort, and improve security and governance.
In the next course, you’ll learn what MCP is, how it works, and how to develop and integrate your own MCP server—unlocking even more powerful and flexible agentic applications.
In this lesson, you learned how to extend your agent’s capabilities by adding both built-in and custom function tools using the OpenAI Agents SDK. You saw how to use the WebSearchTool
for real-time information and how to create your own function tools with the @function_tool
decorator and TypedDicts for clear input schemas. You also learned how to combine multiple tools in a single agent, verify tool registration, and observe how agents use these tools step by step.
You also explored the broader challenges of integrating tools across different agentic systems, and how the Model Context Protocol (MCP) is emerging as a solution to these problems. In the next course, you’ll dive deeper into MCP—learning what it is, how it works, and how to develop and integrate your own MCP server to make your tools universally accessible to any agentic platform.
Now, get ready to put your knowledge into practice with a set of hands-on exercises. These will help you reinforce what you’ve learned by building and using agents with both built-in and custom tools.
