Close Menu
  • Home
  • Opinion
  • Region
    • Africa
    • Asia
    • Europe
    • Middle East
    • North America
    • Oceania
    • South America
  • AI & Machine Learning
  • Robotics & Automation
  • Space & Deep Tech
  • Web3 & Digital Economies
  • Climate & Sustainability Tech
  • Biotech & Future Health
  • Mobility & Smart Cities
  • Global Tech Pulse
  • Cybersecurity & Digital Rights
  • Future of Work & Education
  • Trend Radar & Startup Watch
  • Creator Economy & Culture
What's Hot

Wicklow’s Trinity Biotech secures $25m in SEPA funding

February 28, 2026

BMW Sends AEON Humanoid Robots to the Line in Leipzig

February 28, 2026

Imaginative and prescient GT Idea Noticed in Barcelona, Xiaomi Broadcasts "One Extra Factor" for MWC 2026

February 28, 2026
Facebook X (Twitter) Instagram LinkedIn RSS
NextTech NewsNextTech News
Facebook X (Twitter) Instagram LinkedIn RSS
  • Home
  • Africa
  • Asia
  • Europe
  • Middle East
  • North America
  • Oceania
  • South America
  • Opinion
Trending
  • Wicklow’s Trinity Biotech secures $25m in SEPA funding
  • BMW Sends AEON Humanoid Robots to the Line in Leipzig
  • Imaginative and prescient GT Idea Noticed in Barcelona, Xiaomi Broadcasts "One Extra Factor" for MWC 2026
  • Lenovo Yoga Guide Professional 3D Laptop computer Provides Extremely Immersive Display That Would not Want Particular Glasses
  • Samsung to Improve Auto Blocker for Better Flexibility and Safety on Galaxy Gadgets in 2026
  • Africa’s industrial future requires a distinct type of capital
  • A Coding Implementation to Construct a Hierarchical Planner AI Agent Utilizing Open-Supply LLMs with Software Execution and Structured Multi-Agent Reasoning
  • Samsung’s Galaxy Edge and trifold have unsure futures
Saturday, February 28
NextTech NewsNextTech News
Home - AI & Machine Learning - A Coding Implementation to Construct a Hierarchical Planner AI Agent Utilizing Open-Supply LLMs with Software Execution and Structured Multi-Agent Reasoning
AI & Machine Learning

A Coding Implementation to Construct a Hierarchical Planner AI Agent Utilizing Open-Supply LLMs with Software Execution and Structured Multi-Agent Reasoning

NextTechBy NextTechFebruary 28, 2026No Comments2 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email Copy Link
Follow Us
Google News Flipboard
A Coding Implementation to Construct a Hierarchical Planner AI Agent Utilizing Open-Supply LLMs with Software Execution and Structured Multi-Agent Reasoning
Share
Facebook Twitter LinkedIn Pinterest Email


def executor_agent(step: Dict[str, Any], context: Dict[str, Any]) -> StepResult:
   step_id = int(step.get("id", 0))
   title = step.get("title", f"Step {step_id}")
   device = step.get("device", "llm")


   ctx_compact = {
       "purpose": context.get("purpose"),
       "assumptions": context.get("assumptions", []),
       "prior_results": [
           {"step_id": r.step_id, "title": r.title, "tool": r.tool, "output": r.output[:1500]}
           for r in context.get("outcomes", [])
       ],
   }


   if device == "python":
       code = llm_chat(
           EXECUTOR_SYSTEM,
           consumer=(
               f"Step:n{json.dumps(step, indent=2)}nn"
               f"Context:n{json.dumps(ctx_compact, indent=2)}nn"
               f"Write Python code that completes the step. Output ONLY code."
           ),
           max_new_tokens=700,
           temperature=0.2,
       )
       py = run_python(code)
       out = []
       out.append("PYTHON_CODE:n" + code)
       out.append("nEXECUTION_OK: " + str(py["ok"]))
       if py["stdout"]:
           out.append("nSTDOUT:n" + py["stdout"])
       if py["error"]:
           out.append("nERROR:n" + py["error"])
       return StepResult(step_id=step_id, title=title, device=device, output="n".be part of(out))


   result_text = llm_chat(
       EXECUTOR_SYSTEM,
       consumer=(
           f"Step:n{json.dumps(step, indent=2)}nn"
           f"Context:n{json.dumps(ctx_compact, indent=2)}nn"
           f"Return the step consequence."
       ),
       max_new_tokens=700,
       temperature=0.3,
   )
   return StepResult(step_id=step_id, title=title, device=device, output=result_text)




def aggregator_agent(job: str, plan: Dict[str, Any], outcomes: Record[StepResult]) -> str:
   payload = {
       "job": job,
       "plan": plan,
       "outcomes": [{"step_id": r.step_id, "title": r.title, "tool": r.tool, "output": r.output[:2500]} for r in outcomes],
   }
   return llm_chat(
       AGGREGATOR_SYSTEM,
       consumer=f"Mix every little thing into the ultimate reply.nnINPUT:n{json.dumps(payload, indent=2)}",
       max_new_tokens=900,
       temperature=0.2,
   )




def run_hierarchical_agent(job: str, verbose: bool = True) -> Dict[str, Any]:
   plan = planner_agent(job)


   if verbose:
       print("n====================")
       print("PLAN (from Planner)")
       print("====================")
       print(json.dumps(plan, indent=2))


   context = {
       "purpose": plan.get("purpose", job),
       "assumptions": plan.get("assumptions", []),
       "outcomes": [],
   }


   outcomes: Record[StepResult] = []
   for step in plan.get("steps", []):
       res = executor_agent(step, context)
       outcomes.append(res)
       context["results"].append(res)


       if verbose:
           print("n--------------------")
           print(f"STEP {res.step_id}: {res.title}  [tool={res.tool}]")
           print("--------------------")
           print(res.output)


   ultimate = aggregator_agent(job, plan, outcomes)
   if verbose:
       print("n====================")
       print("FINAL (from Aggregator)")
       print("====================")
       print(ultimate)


   return {"job": job, "plan": plan, "outcomes": outcomes, "ultimate": ultimate}




demo_task = """
Create a sensible guidelines to launch a small multi-agent system in Python for coordinating logistics:
- One planner agent that decomposes duties
- Two executor brokers (routing + stock)
- A easy reminiscence retailer for previous choices
Maintain it light-weight and runnable in Colab.
"""


_ = run_hierarchical_agent(demo_task, verbose=True)


print("nnType your personal job (or press Enter to skip):")
user_task = enter().strip()
if user_task:
   _ = run_hierarchical_agent(user_task, verbose=True)

Elevate your perspective with NextTech Information, the place innovation meets perception.
Uncover the most recent breakthroughs, get unique updates, and join with a worldwide community of future-focused thinkers.
Unlock tomorrow’s traits right now: learn extra, subscribe to our publication, and turn out to be a part of the NextTech neighborhood at NextTech-news.com

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
NextTech
  • Website

Related Posts

Google DeepMind Introduces Unified Latents (UL): A Machine Studying Framework that Collectively Regularizes Latents Utilizing a Diffusion Prior and Decoder

February 28, 2026

The way to Construct Interactive Geospatial Dashboards Utilizing Folium with Heatmaps, Choropleths, Time Animation, Marker Clustering, and Superior Interactive Plugins

February 28, 2026

Sakana AI Introduces Doc-to-LoRA and Textual content-to-LoRA: Hypernetworks that Immediately Internalize Lengthy Contexts and Adapt LLMs by way of Zero-Shot Pure Language

February 27, 2026
Add A Comment
Leave A Reply Cancel Reply

Economy News

Wicklow’s Trinity Biotech secures $25m in SEPA funding

By NextTechFebruary 28, 2026

The NASDAQ-listed firm can entry discretionary funds by means of a 36-month settlement with New…

BMW Sends AEON Humanoid Robots to the Line in Leipzig

February 28, 2026

Imaginative and prescient GT Idea Noticed in Barcelona, Xiaomi Broadcasts "One Extra Factor" for MWC 2026

February 28, 2026
Top Trending

Wicklow’s Trinity Biotech secures $25m in SEPA funding

By NextTechFebruary 28, 2026

The NASDAQ-listed firm can entry discretionary funds by means of a 36-month…

BMW Sends AEON Humanoid Robots to the Line in Leipzig

By NextTechFebruary 28, 2026

BMW workers on the Leipzig plant have been juggling all of the…

Imaginative and prescient GT Idea Noticed in Barcelona, Xiaomi Broadcasts "One Extra Factor" for MWC 2026

By NextTechFebruary 28, 2026

On February 28, Xiaomi introduced through its official X account on the…

Subscribe to News

Get the latest sports news from NewsSite about world, sports and politics.

NEXTTECH-LOGO
Facebook X (Twitter) Instagram YouTube

AI & Machine Learning

Robotics & Automation

Space & Deep Tech

Web3 & Digital Economies

Climate & Sustainability Tech

Biotech & Future Health

Mobility & Smart Cities

Global Tech Pulse

Cybersecurity & Digital Rights

Future of Work & Education

Creator Economy & Culture

Trend Radar & Startup Watch

News By Region

Africa

Asia

Europe

Middle East

North America

Oceania

South America

2025 © NextTech-News. All Rights Reserved
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms Of Service
  • Advertise With Us
  • Write For Us
  • Submit Article & Press Release

Type above and press Enter to search. Press Esc to cancel.

Subscribe For Latest Updates

Sign up to best of Tech news, informed analysis and opinions on what matters to you.

Invalid email address
 We respect your inbox and never send spam. You can unsubscribe from our newsletter at any time.     
Thanks for subscribing!