OrionAboutResources
Back to resourcesHow to Create an AI Planner Agent: Part 2
Leah BonserLeah Bonser
AI

How to Create an AI Planner Agent: Part 2

Introduction

In Part 1, we explored how to create an effective AI planner agent by using task decomposition. We demonstrated how breaking tasks into manageable subtasks helps agents handle complex workflows more efficiently. In this second part, we’ll build on that foundation by introducing hierarchical planning, which enables AI agents to manage even more intricate workflows through modular task delegation.

Connecting Modules for Complex Tasks

In a hierarchical planning system, multiple modules collaborate to handle different layers of a task. The key is how these modules are interconnected. The upper module focuses on decomposing high-level tasks into smaller parts, while the lower modules execute those specific actions, which are then fed back to the upper module for final completion.

For example, let’s revisit the task of retrieving the birthdates of The Beatles that we discussed in Part 1:

  1. Upper Module: This module generates the overall plan and assigns subtasks to find each band member’s birthdate.
  2. Lower Module: Each individual query is passed to a lower module, which retrieves the relevant information (using a search tool like the Bing API or internal data).
  3. Return Path: The results are returned to the upper module, which compiles them into the final response.

This process keeps the upper module focused on managing the workflow while the lower modules handle detailed data retrieval.

Maintaining Attention Throughout the Task

As tasks become more complex, managing the flow of information between modules becomes essential. Without effective control, an AI agent’s context window can become overwhelmed, leading to errors or incomplete outputs.

Hierarchical planning helps by ensuring that only the necessary information is passed between modules. Each module focuses on executing its specific task and returning only actionable results, reducing the agent's cognitive load and keeping its attention focused.

For instance, when querying The Beatles' birthdates, the upper module only needs to know the final results—not the detailed search logs. By minimizing unnecessary information, we ensure the agent stays efficient and precise.

A Real-World Example: Essay Writing AI

Hierarchical planning excels in token-intensive tasks like essay writing. Dividing the process into smaller components helps manage complexity and token limits.

Here’s how it works:

  1. Create an essay file.
  2. Write the introduction.
  3. Generate body paragraphs.
  4. Write the conclusion.
  5. Review and refine the essay.

A specific module manages each part of the essay. For example, the module generating the introduction returns a simple message: “The introduction has been successfully written.” The upper module doesn’t need to see the underlying code or API calls—it only receives confirmation that the task was completed.

Exec Proxy

This modular structure prevents the AI from being overwhelmed by the entire essay-writing process and allows it to maintain focus on generating coherent, relevant content.

Modular System

Hierarchical Nested Planning for Complex Workflows

Hierarchical nested planning allows AI agents to handle even more complex, multi-layered tasks. The upper module focuses on task coordination, while the lower modules tackle detailed execution.

Consider the essay-writing AI again. The upper module manages the high-level tasks like generating sections and reviewing the essay, while lower modules handle the specifics of text generation. This approach keeps the agent focused on its primary tasks while delegating complex processing to lower layers.

Application to Other Workflows:

  • Customer Service Automation: An upper module can handle general inquiries, while lower modules handle specific customer requests, such as retrieving order information or processing payments.
  • Project Management: An AI agent can coordinate tasks among team members, with upper modules assigning tasks and lower modules tracking progress and deadlines.
  • Data Retrieval and Analysis: In cases where data retrieval is resource-intensive, the upper module manages the overall process, while lower modules perform detailed searches and data extraction.

Token Management: Keeping Your AI Efficient

Managing tokens efficiently is critical for AI agents, especially when dealing with large datasets or complex workflows. By employing hierarchical planning, we can limit how many tokens are passed between modules, ensuring that only essential information is included.

Without hierarchical planning, the AI would need to manage the entire data flow, risking token exhaustion or overloading the system with irrelevant information. Instead, by limiting token usage at each level, the system can complete its tasks without exceeding the context window.

Conclusion

In this article, we’ve shown how hierarchical planning can elevate AI agents to handle more complex tasks efficiently. By breaking tasks into smaller modules, we ensure that the agent stays focused, manages tokens effectively, and handles even intricate workflows with ease.

Whether it’s retrieving information, writing an essay, or managing customer service inquiries, hierarchical planning provides a scalable and structured approach to AI task management. Want to see this in action? Try it yourself using the notebook linked below!

GitHub Link to Notebook

We’d love to hear how you’re using hierarchical planning in your own workflows. Feel free to share your experiences and insights with us!