Welcome! Today, we’ll see how to make your AI agents more useful by giving them access to simple tools. Imagine a personal assistant who can only answer from memory. Now, give them a smartphone — they can look up anything!
In this lesson, you’ll learn to equip agents with tools, like web search, so they can find up-to-date information and do more than just answer from built-in knowledge. By the end, you’ll know how to add and use simple tools to make your agents more powerful and relevant.
What are “tools” for AI agents? In AI, a tool is an external function or service the agent can use for specific tasks — like searching the web, sending emails, or doing calculations.
Why is this useful? For example, a customer support chatbot limited to its training data can quickly become outdated. But with a web search or knowledge base tool, it can provide accurate, current answers.
In the Agents SDK, tools are objects you attach to your agent. When the agent gets a user request, it can use its tools to generate better responses.
The agent doesn’t use tools automatically for every question — it decides when to call a tool based on the instructions you provide and the descriptions of the tools themselves. When you define your agent, you guide its behavior with clear instructions (like “Use the web search tool to answer questions about current events”). The agent reads these instructions and, together with the tool’s description, determines whether a user’s request requires using a tool or can be answered from its own knowledge.
This means that the quality of your instructions and tool descriptions directly affects how and when the agent uses its tools. If you want your agent to use a tool for certain types of questions, make that explicit in the instructions. For example, you might write: “If you don’t know the answer or if the question is about recent events, use the web search tool.” This helps the agent make better decisions and gives you more control over its behavior.
Let’s see this in action. We’ll add a web search tool to an agent, letting it look up information online.
Here’s what’s happening: We import Agent, Runner, and WebSearchTool. We create an agent named "Web Search Agent" with the WebSearchTool. The instructions guide the agent’s behavior. We provide a user input, such as "Latest news about AI," run the agent, and print the output. This lets the agent use the web search tool when it needs information it doesn’t already know.
When you run the code, the agent gets the user’s question and decides if it needs the web search tool. For "latest news," it recognizes a search is needed. The agent calls WebSearchTool, fetches information from the web, processes the results, and generates a response. It’s like you using Google when you need more information. Tools make your agent much more flexible.
Here’s another example with a different question:
Now, the agent uses the web search tool to answer who won the last Super Bowl. This shows how the agent can handle a wide range of real-world questions.
To sum up, you’ve learned how to enhance agents by giving them tools. Tools let agents do more than just answer from memory — they can search, calculate, and more. By attaching tools and giving clear instructions, your agents become much more useful.
Now it’s your turn! Next, you’ll practice adding and using tools with your own agents. This hands-on work will help you master these concepts and build more advanced AI solutions. Let’s get started!
