Treating Agents as Callable Tools

Introduction & Lesson Overview

Welcome back! In the last two lessons, you learned how to make your OpenAI agents more capable by integrating both hosted tools (like the webSearchTool) and your own custom function tools. These skills allow your agents to access real-time information and perform custom logic, such as calculating a travel budget.

Today, you will take the next step in building modular and maintainable AI systems: turning agents themselves into reusable tools. This approach allows you to create specialized agents for specific tasks and then orchestrate them from a central, main agent. By the end of this lesson, you will know how to convert an agent into a callable tool, add it to another agent’s tool list, and run a workflow in which the main agent delegates tasks to its specialized agent-tools. This modular design is a powerful way to build complex, flexible AI applications.

Recap: From Function Tools to Agent Tools

Let’s quickly review what you have learned so far. In the previous lesson, you saw how to create custom function tools in TypeScript by using the tool function and defining input schemas with zod. This allowed you to register tools with your agent, enabling it to perform custom logic — such as estimating a travel budget — in addition to using hosted tools like webSearchTool.

Now, imagine you want to break down your agent’s responsibilities even further. Instead of having one agent do everything, you can create smaller, specialized agents — each focused on a specific task, such as research or calculations. By turning these agents into callable tools, you can have a central agent delegate tasks to them as needed. This not only keeps your code organized but also makes it easier to maintain and extend your system in the future.

Similarities to Handoffs

While using agents as tools and handoffs both involve interactions between agents, they serve different purposes:

  • Agents as Tools: The central agent retains control and invokes other agents as tools to perform specific tasks. This approach is suitable when the primary agent needs to utilize the capabilities of specialized agents without transferring control.
  • Handoffs: The primary agent delegates control to another agent, effectively transferring the conversation or task to the specialized agent. This method is useful when a task or query is best handled entirely by another agent.

In summary, using agents as tools allows for the integration of specialized agents into a workflow while maintaining control within the central agent, whereas handoffs involve transferring control to another agent to handle specific tasks or queries.

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