Introduction & Context

Welcome to your next step in mastering OpenAI agents! In the previous course, you learned how to coordinate multiple agents and customize how they hand off tasks to each other. You practiced enforcing input validation and running custom logic during these handoffs, making your agent workflows more robust and reliable.

Now, you are ready to expand your agents’ abilities even further. In this lesson, you will learn how to give your agents access to real-time information and external data by integrating OpenAI hosted tools. This is a major step forward: while agents are already powerful at reasoning and following instructions, their knowledge is limited to what was available at the time their model was trained. Tool, such as the OpenAI hosted WebSearchTool, allow your agents to reach out to the web and other sources, making them much more useful for real-world tasks that require up-to-date information.

By the end of this lesson, you will know how to equip your agents with hosted tools and see how this changes what they can do. Let’s get started by understanding what hosted tools are and why they matter.

Extending Agent Capabilities With Tools

While LLMs can reason and generate text, they are limited not only in their knowledge, which is restricted to their training data, but also in their ability to take action. By connecting to tools, agents can go beyond these limitations—taking real action by accessing real-time information, performing calculations, or interacting with external systems to accomplish tasks.

There are several types of tools agents can use:

  • Built-in tools: These come with the agent library or platform.
  • Hosted tools: Tools provided and managed by third parties, such as OpenAI.
  • Custom tools: Tools you create yourself, allowing agents to connect to your own APIs, databases, or business logic.

When you give an agent access to tools, you list them in its configuration. The agent then decides, based on the user’s request and its own reasoning, when and how to use each tool. It can call a tool, use the result, and combine that information with its own knowledge to generate a final answer.

This ability to use tools is what transforms an agent from a static LLM into a dynamic assistant that can solve real-world problems and provide up-to-date, actionable information.

OpenAI Hosted Tools

Hosted tools in the OpenAI Agents SDK are special, pre-built tool classes provided and maintained by OpenAI. These tools run on OpenAI’s infrastructure alongside the language models, so you don’t need to set up or host anything yourself. Unlike custom tools that you define in your own code, hosted tools are ready to use out of the box—just import them from the SDK and add them to your agent’s configuration. They enable your agents to interact with external data sources, access real-time information, and perform actions that go beyond basic text generation.

The most common hosted tools include:

  • WebSearchTool: Lets agents perform web searches to find the latest information online.
  • FileSearchTool: Allows agents to search through internal documents stored in OpenAI’s vector stores.
  • ComputerTool: Enables agents to perform basic computer operations, like managing files.

In this lesson, we will focus on the WebSearchTool, which is the easiest way to let your agent answer questions about current events, trends, or anything that requires up-to-date knowledge. This tool is especially useful for travel, research, news, and many other applications where static knowledge is not enough.

Integrating a Hosted Tool

To enable your agent to access real-time information, you can simply add the WebSearchTool to its configuration. This is done by passing a list of tool objects to the tools parameter when creating your agent. Here’s how you can set up a travel assistant agent with web search capabilities:

By including WebSearchTool() in the tools list, you allow your agent to perform live web searches. This means it can answer questions about current events, weather, or travel recommendations using up-to-date information from the internet.

Seeing the Tool in Action

Let’s see how the agent uses the tool to answer a specific, time-sensitive question. This query is a perfect example of something a language model alone cannot answer accurately, since the best skiing destinations change with the season and current conditions. By using the WebSearchTool, the agent can look up the latest information and provide a relevant, up-to-date recommendation.

When you run this code, the agent receives the user’s query, recognizes that it needs current information, and automatically uses the WebSearchTool to search the web for the best skiing destinations for this month. The agent then combines the search results with its own reasoning to generate a helpful answer. The output might look like this:

Notice how the agent’s answer is tailored to the current month, and it cites up-to-date sources from the web. The agent determines the current date, searches the web for the latest information, and pulls details directly from relevant websites. This ability to gather and synthesize real-time data is only possible because the agent used the hosted tool in response to the user’s specific, time-sensitive query.

Inspecting Tool Use

In addition to seeing the agent’s final answer, you can also inspect how the agent handled the query and used its tools during the conversation. The result.to_input_list() method provides a step-by-step breakdown of the agent’s actions, including the original user query, the tool call, and the final response.

The output will show each step, such as the user’s input, the agent’s decision to call the web search tool, and the final message with citations:

This breakdown makes it clear how the agent responded to the user’s specific, time-sensitive query by using the WebSearchTool to gather the latest information before composing its final answer.

Summary & Next Steps

In this lesson, you learned how to expand your agent’s abilities by integrating OpenAI hosted tools, with a focus on the WebSearchTool. You saw how easy it is to add a hosted tool to your agent’s configuration, and how this allows your agent to access real-time information from the web. You also learned how to run your agent and interpret its output, including the steps it took to use the tool.

You are now ready to practice these skills in the CodeSignal environment. Remember, all the necessary libraries and tools are already installed for you here, so you can focus on building and experimenting with your agents. In the next exercises, you will get hands-on experience adding hosted tools to agents and seeing the difference they make. Congratulations on reaching this point — let’s keep building!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal