✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: February 28, 2026
  • 7 min read

Hierarchical AI Planner: Open-Source Implementation for Multi‑Agent Execution

A hierarchical AI planner is a multi‑agent system that decomposes a high‑level objective into a series of concrete steps, runs each step with the appropriate tool (LLM reasoning, Python execution, or external APIs), and then aggregates the partial results into a polished final answer.

How the New Hierarchical Planner AI Agent Transforms Multi‑Agent Reasoning

The recent MarkTechPost tutorial sparked a wave of interest in building autonomous agents that can plan, execute, and synthesize results without human supervision. In this article we break down the core concepts, walk through the key implementation details, and show why the hierarchical AI planner is quickly becoming a cornerstone of AI automation for developers, product managers, and tech enthusiasts.

UBOS, a leading Enterprise AI platform, already offers a suite of tools that make it easy to prototype such agents. By combining open‑source LLMs, tool execution, and a visual workflow studio, you can spin up a full‑stack multi‑agent solution in minutes.

Hierarchical AI Planner Diagram

What Is a Hierarchical Planner AI Agent?

At its essence, a hierarchical planner consists of three cooperating agents:

  • Planner Agent – receives the user’s goal and outputs a JSON‑structured plan with 3‑8 independent steps.
  • Executor Agent – runs each step using the most suitable tool (LLM reasoning, Python code, or an external API).
  • Aggregator Agent – stitches the step outputs together, formats them, and returns the final answer.

This architecture follows the MECE principle (Mutually Exclusive, Collectively Exhaustive), ensuring that each step is self‑contained while the whole plan covers the entire problem space.

Because the planner emits strict JSON, downstream components can reliably parse the plan, making the system robust to hallucinations—a common pain point when using open‑source LLMs for complex workflows.

Implementation Blueprint: From Code to Production

1️⃣ Setting Up the Model

UBOS recommends the OpenAI ChatGPT integration for quick prototyping, but the tutorial uses the open‑source Qwen/Qwen2.5‑1.5B‑Instruct model to keep costs low. The following snippet shows how to load the model with 4‑bit quantization when a GPU is available:

pip install -U transformers accelerate bitsandbytes sentencepiece
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

MODEL_ID = "Qwen/Qwen2.5-1.5B-Instruct"
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"

tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID,
    device_map="auto",
    torch_dtype="auto",
    load_in_4bit=True,
).to(DEVICE)
model.eval()

2️⃣ Defining the Interaction Functions

The llm_chat helper builds a system‑user prompt pair, sends it to the model, and returns the assistant’s raw text. A separate run_python sandbox safely executes generated Python code and captures stdout/stderr.

def llm_chat(system, user, max_new_tokens=500, temperature=0.3):
    messages = [{"role":"system","content":system},{"role":"user","content":user}]
    prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    out = model.generate(
        **inputs,
        max_new_tokens=max_new_tokens,
        do_sample=temperature>0,
        temperature=temperature,
        top_p=0.9,
        repetition_penalty=1.05,
        eos_token_id=tokenizer.eos_token_id,
    )
    return tokenizer.decode(out[0], skip_special_tokens=True).split(user)[-1].strip()

3️⃣ Planner Prompt & JSON Schema

The planner’s system prompt forces a JSON output that matches this schema:

{
  "goal": "string",
  "assumptions": ["string", ...],
  "steps": [
    {
      "id": 1,
      "title": "short title",
      "instruction": "what to do",
      "tool": "none|llm|python",
      "expected_output": "desired result"
    },
    ...
  ]
}

Because the schema is explicit, the Chroma DB integration can store each plan as a vector for later retrieval, enabling “memory” across sessions.

4️⃣ Executor Logic

The executor decides whether to call the LLM again or to run Python. When tool="python", it sends the generated code to run_python and returns a structured result object.

5️⃣ Aggregator Prompt

The aggregator receives a payload containing the original task, the plan, and all step results. Its job is to produce a concise, human‑readable answer, optionally adding bullet points, tables, or actionable next steps.

6️⃣ Orchestrating the Workflow

The top‑level run_hierarchical_agent function ties everything together. It prints the plan, iterates over steps, collects results, and finally calls the aggregator. The entire pipeline can be wrapped in a Workflow automation studio visual node, letting non‑programmers drag‑and‑drop the three agents.

Why Adopt a Hierarchical Planner? Benefits & Real‑World Use‑Cases

The hierarchical approach solves several pain points that plague single‑agent designs:

  • Scalability – Each step runs independently, allowing parallel execution on a cluster or serverless functions.
  • Reliability – JSON‑based plans make error handling deterministic; a failed step can be retried without re‑planning.
  • Transparency – Stakeholders can inspect the plan JSON to understand exactly how the AI intends to solve the problem.
  • Tool Flexibility – By declaring tool per step, you can seamlessly mix LLM reasoning, code execution, or external APIs (e.g., Telegram integration on UBOS for notifications).
  • Reusability – Plans can be stored in UBOS portfolio examples and reused across projects.

Industry Scenarios

Domain Typical Goal Planner Advantage
E‑commerce Generate a seasonal promotion calendar Breaks marketing strategy into copywriting, budget allocation, and channel scheduling – each step can be executed by specialized agents.
Supply Chain Optimize routing for a fleet of delivery trucks Planner creates separate routing, load‑balancing, and risk‑assessment steps; executor runs Python simulations for each.
Customer Support Automate ticket triage and response drafting Combines LLM classification, knowledge‑base lookup (via ElevenLabs AI voice integration for voice replies), and escalation routing.

Startups can leverage the UBOS for startups plan templates, while SMBs benefit from the UBOS solutions for SMBs that bundle planner, executor, and aggregator into a single SaaS offering.

Understanding the Illustration: A Visual Walkthrough

The diagram above (generated by UBOS’s AI image service) visualizes the three‑layer flow:

  1. Input Layer – User prompt enters the Planner Agent.
  2. Processing Layer – The Planner emits a JSON plan; each step is dispatched to an Executor (LLM or Python sandbox).
  3. Output Layer – The Aggregator compiles step results into the final response, which can be sent back to the user or to downstream systems (e.g., a Web app editor on UBOS UI).

Notice the color‑coded arrows: blue for LLM reasoning, green for code execution, and orange for external API calls. This visual cue helps developers quickly spot bottlenecks and decide where to inject custom tools.

Read the Full Original Tutorial

For a line‑by‑line walkthrough, see the original MarkTechPost piece: Hierarchical Planner AI Agent Tutorial. The article includes the complete source code, a live Colab notebook, and performance benchmarks on various hardware configurations.

Explore More UBOS Resources

UBOS provides a rich ecosystem that complements the hierarchical planner approach. Below are curated links to dive deeper:

Conclusion: The Future Is Hierarchical

By separating planning, execution, and aggregation into dedicated agents, the hierarchical AI planner delivers a robust, transparent, and extensible framework for AI automation. Whether you are a startup building a niche chatbot, an SMB looking to automate routine reporting, or an enterprise architect designing a fleet of autonomous agents, the pattern scales gracefully.

UBOS’s low‑code Workflow automation studio and extensive UBOS platform overview make it trivial to prototype, test, and deploy hierarchical planners in production. Combine this with the ChatGPT and Telegram integration for instant user feedback, and you have a full‑stack solution that turns complex goals into actionable outcomes—automatically.

Ready to build your own hierarchical planner? Start with the UBOS templates for quick start and let the platform handle the heavy lifting.


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.