Lesson Introduction

Think of managing a team where each member has a unique skill — one searches the web, another reads files, and you, as the manager, assign tasks. In AI, you can build a similar setup: agents with specific abilities, and an orchestrator agent that delegates tasks.

In this lesson, you'll learn how to use an agent as a tool for another agent. This lets you combine the strengths of multiple agents, making your AI solutions modular and powerful. By the end, you'll know how to wrap agents as tools, orchestrate their collaboration, and run complex workflows with just a few lines of code.

Agents as Tools: The Concept and Wrapping Agents

The main idea is using an agent as a tool. In real life, you might ask a colleague to handle a task because they have the right expertise. In software, you can create agents that are experts in certain domains — like searching the web or reading files — and use them as tools for a higher-level agent.

Why do this?

  • Modularity: Each agent focuses on one job, making code easier to manage.
  • Reusability: Specialized agents can be reused in different projects.
  • Separation of Concerns: Agents can be developed and tested independently.

For example, to answer questions that need both web search and file reading, you can create two specialized agents and an orchestrator agent that knows when to use each.

To use an agent as a tool, you "wrap" it so another agent can call it like any other tool. The Agents SDK provides .as_tool() for this.

Here’s a basic example. Suppose you have a web search agent:

To make this agent available as a tool:

Now, web_search_tool can be added to another agent’s tools. The tool_name and tool_description help the orchestrator agent know what this tool does. You can do the same with any agent, including custom ones. For example, a filesystem agent that reads files can also be wrapped as a tool.

Building an Orchestrator Agent

An orchestrator agent is like a project manager. It doesn’t do the specialized work itself, but knows which agent to call for each task. You build it by adding other agents (wrapped as tools) to its tools list.

Example:

The orchestrator’s instructions should explain when and how to use each tool. This helps the agent make the right decisions.

A real-life analogy: In a support center, the main agent (orchestrator) receives a question and forwards it to the right department (specialized agent). The orchestrator agent works the same way, routing tasks to the right specialist.

Running the Orchestrator Agent

Once your orchestrator agent is set up, you interact with it like any other agent. The orchestrator decides which tool (specialized agent) to use for each request.

Example:

When you run this, the orchestrator agent analyzes your request. If you ask about the weather, it uses the web search agent. If you ask about a file, it uses the filesystem agent. This delegation is automatic, based on the tools and instructions you provided.

This approach is powerful because you can add more specialized agents as needed — like a translation agent or a math solver agent.

Lesson Summary and Practice Introduction

You’ve learned how to use agents as tools for other agents: how to wrap agents with .as_tool(), build an orchestrator agent that delegates tasks, and run complex workflows with clear, maintainable code. This modular approach mirrors real teamwork and makes your AI solutions flexible and scalable.

Now, it’s your turn to practice. In the next section, you’ll build and run your own orchestrator agent, combining specialized agents to solve real-world problems. This hands-on work will help you solidify your understanding and prepare for more advanced agent orchestration.

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