Lesson Introduction

Welcome! Today, we’ll see how to orchestrate multiple agents in a loop — a key skill for building real-world AI systems. Imagine managing a team: one member tracks your tasks, another helps you learn. How do you coordinate them to handle requests one after another? That’s our focus.

By the end, you’ll know how to set up a manager agent that coordinates other agents, processes user requests in sequence, and delegates tasks efficiently. This is essential for building multi-agent systems, from productivity tools to intelligent assistants.

The Role of a Manager Agent

Let’s clarify what a manager agent is and why it matters. In a multi-agent system, each agent is specialized:

  • A Todo Agent manages your tasks.
  • A Learning (RAG) Agent helps with learning materials.

To handle varied user requests — like “List all my tasks” or “What are my learning plans for React?” — you need a coordinator. The manager agent fills this role, listening to the user, picking the right agent for the job, and delegating. This keeps your system organized and scalable.

Here’s a simple manager agent setup:

This lets the manager agent use both the Todo Agent and the RAG Agent as needed.

Setting Up the Orchestration Loop

To process multiple user requests, we use a loop. Users rarely stop after one question — they interact in a sequence. The loop keeps asking for input, processes it, and stops only when the user says so.

In this setup, the orchestration loop is implemented in a function called run_manager_agent, which takes a list of user requests and processes them one by one. Here’s how it looks:

And you call this function from your main script:

  • The loop simulates a conversation with a list of user inputs.
  • “exit” or “quit” ends the loop.
  • Otherwise, the manager agent processes the input and prints the result.

This pattern is common in chatbots and interactive tools.

Delegating Tasks to Sub-Agents

How does the manager agent pick the right sub-agent? The orchestration logic is in the tools. Each tool wraps a sub-agent’s functionality. The manager agent analyzes the user request and picks the right tool.

For example, “List all my tasks” goes to the Todo Agent. “What are my learning plans for React?” goes to the RAG Agent.

Tools are registered like this:

Delegation happens here:

Collecting and Returning Results

After a sub-agent finishes, the manager agent collects the result and returns it to the user — like a project manager reporting back to a client.

In our example, the result is printed:

Note: The manager agent’s response is not just a raw JSON object. Instead, it is a nicely formatted LLM response, often in natural language, summarizing or presenting the information in a user-friendly way.

A full example:

Example output:

Running this, you’ll see the manager agent process each input, delegate to the right sub-agent, and print results — until “exit.”

Lesson Summary and Practice Introduction

You’ve learned how to orchestrate multiple agents in a loop using a manager agent. We covered:

  • The purpose and structure of a manager agent
  • Processing a sequence of user requests in a loop
  • How the manager agent delegates to sub-agents
  • Collecting and returning results in a user-friendly, LLM-generated format

This pattern is key for scalable, maintainable multi-agent systems.

Now it’s your turn! Next, you’ll practice building and running your own orchestration loop. You’ll coordinate agents, process user requests, and return results — just like in a real AI system. Let’s get started!

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