Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Mind Body Spirit Tree

    March 11, 2026

    All Slay The Spire 2 Bosses

    March 11, 2026

    Tameer i Wattan Public School & College Abbottabad Jobs 2026 2026 Job Advertisement Pakistan

    March 11, 2026
    Facebook X (Twitter) Instagram
    Wednesday, March 11
    Trending
    • Mind Body Spirit Tree
    • All Slay The Spire 2 Bosses
    • Tameer i Wattan Public School & College Abbottabad Jobs 2026 2026 Job Advertisement Pakistan
    • Magnetic Messaging: Sizzling provide for a sizzling market- Excessive Conversions
    • The Curator: 10 best face sunscreens to try in 2026 – National
    • What are “sleeper cells” and why are intelligence agencies concerned?
    • ICC denies unfair treatment of squads stranded in India after T20 World Cup amid Middle East crisis
    • Medical health insurance startup Alan reaches €5B valuation
    • UK job vacancies decline slows as service sector progress indicators early labour market restoration
    • Discover Jaggery Benefits For Health And Weight Loss
    Facebook X (Twitter) Instagram Pinterest Vimeo
    The News92The News92
    • Home
    • World
    • National
    • Sports
    • Crypto
    • Travel
    • Lifestyle
    • Jobs
    • Insurance
    • Gaming
    • AI & Tech
    • Health & Fitness
    The News92The News92
    Home - AI & Tech - How to Build a Self-Designing Meta-Agent That Automatically Constructs, Instantiates, and Refines Task-Specific AI Agents
    AI & Tech

    How to Build a Self-Designing Meta-Agent That Automatically Constructs, Instantiates, and Refines Task-Specific AI Agents

    Naveed AhmadBy Naveed AhmadMarch 11, 2026No Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    class MetaAgent:
       def __init__(self, llm: Optional[LocalLLM] = None):
           self.llm = llm or LocalLLM()
    
    
       def _capability_heuristics(self, task: str) -> Dict[str, Any]:
           t = task.lower()
    
    
           needs_data = any(k in t for k in ["csv", "dataframe", "pandas", "dataset", "table", "excel"])
           needs_math = any(k in t for k in ["calculate", "compute", "probability", "equation", "optimize", "derivative", "integral"])
           needs_writing = any(k in t for k in ["write", "draft", "email", "cover letter", "proposal", "summarize", "rewrite"])
           needs_analysis = any(k in t for k in ["analyze", "insights", "trend", "compare", "benchmark"])
           needs_memory = any(k in t for k in ["long", "multi-step", "remember", "plan", "workflow", "pipeline"])
    
    
           return {
               "needs_data": needs_data,
               "needs_math": needs_math,
               "needs_writing": needs_writing,
               "needs_analysis": needs_analysis,
               "needs_memory": needs_memory,
           }
    
    
       def design(self, task_description: str) -> AgentConfig:
           caps = self._capability_heuristics(task_description)
           tools = default_tool_registry()
    
    
           selected: List[ToolSpec] = []
           selected.append(ToolSpec(
               name="calc",
               description="Evaluate a safe mathematical expression (no arbitrary code).",
               inputs_schema={"type":"object","properties":{"expression":{"type":"string"}}, "required":["expression"]}
           ))
           selected.append(ToolSpec(
               name="text_stats",
               description="Compute basic statistics about a text blob (words, lines, unique words).",
               inputs_schema={"type":"object","properties":{"text":{"type":"string"}}, "required":["text"]}
           ))
           if caps["needs_data"]:
               selected.append(ToolSpec(
                   name="csv_profile",
                   description="Load a CSV from a local path and print a quick profile (head, describe).",
                   inputs_schema={"type":"object","properties":{"path":{"type":"string"},"n_rows":{"type":"integer"}}, "required":["path"]}
               ))
    
    
           if caps["needs_memory"] or caps["needs_analysis"] or caps["needs_data"]:
               mem = MemorySpec(kind="retrieval_tfidf", max_items=250, retrieval_k=6)
           else:
               mem = MemorySpec(kind="scratchpad", max_items=120, retrieval_k=5)
    
    
           if caps["needs_analysis"] or caps["needs_data"] or caps["needs_memory"]:
               planner = PlannerSpec(kind="react", max_steps=12, temperature=0.2)
           else:
               planner = PlannerSpec(kind="react", max_steps=8, temperature=0.2)
    
    
           objective = "Solve the user task with tool use when helpful; produce a clean final response."
           cfg = AgentConfig(
               agent_name="AutoDesignedAgent",
               objective=objective,
               planner=planner,
               memory=mem,
               tools=selected,
               output_style="concise",
           )
    
    
           for ts in selected:
               if not tools.has(ts.name):
                   raise RuntimeError(f"Tool selected but not registered: {ts.name}")
    
    
           return cfg
    
    
       def instantiate(self, cfg: AgentConfig) -> AgentRuntime:
           tools = default_tool_registry()
           if cfg.memory.kind == "retrieval_tfidf":
               mem = TfidfRetrievalMemory(max_items=cfg.memory.max_items, retrieval_k=cfg.memory.retrieval_k)
           else:
               mem = ScratchpadMemory(max_items=cfg.memory.max_items)
           return AgentRuntime(config=cfg, llm=self.llm, tools=tools, memory=mem)
    
    
       def evaluate(self, task: str, answer: str) -> Dict[str, Any]:
           a = (answer or "").strip().lower()
           flags = {
               "empty": len(a) == 0,
               "generic": any(p in a for p in ["i can't", "cannot", "missing", "provide more details", "parser fallback"]),
               "mentions_max_steps": "max steps" in a,
           }
           score = 1.0
           if flags["empty"]: score -= 0.6
           if flags["generic"]: score -= 0.25
           if flags["mentions_max_steps"]: score -= 0.2
           score = max(0.0, min(1.0, score))
           return {"score": score, "flags": flags}
    
    
       def refine(self, cfg: AgentConfig, eval_report: Dict[str, Any], task: str) -> AgentConfig:
           new_cfg = cfg.model_copy(deep=True)
    
    
           if eval_report["flags"]["generic"] or eval_report["flags"]["mentions_max_steps"]:
               new_cfg.planner.max_steps = min(18, new_cfg.planner.max_steps + 6)
               new_cfg.planner.temperature = min(0.35, new_cfg.planner.temperature + 0.05)
               if new_cfg.memory.kind != "retrieval_tfidf":
                   new_cfg.memory.kind = "retrieval_tfidf"
                   new_cfg.memory.max_items = max(new_cfg.memory.max_items, 200)
                   new_cfg.memory.retrieval_k = max(new_cfg.memory.retrieval_k, 6)
    
    
           t = task.lower()
           if any(k in t for k in ["csv", "dataframe", "pandas", "dataset", "table"]):
               if not any(ts.name == "csv_profile" for ts in new_cfg.tools):
                   new_cfg.tools.append(ToolSpec(
                       name="csv_profile",
                       description="Load a CSV from a local path and print a quick profile (head, describe).",
                       inputs_schema={"type":"object","properties":{"path":{"type":"string"},"n_rows":{"type":"integer"}}, "required":["path"]}
                   ))
    
    
           return new_cfg
    
    
       def build_and_run(self, task: str, improve_rounds: int = 1, verbose: bool = True) -> Tuple[str, AgentConfig]:
           cfg = self.design(task)
           agent = self.instantiate(cfg)
    
    
           if verbose:
               print("\n==============================")
               print("META-AGENT: DESIGNED CONFIG")
               print("==============================")
               print(cfg.model_dump_json(indent=2))
    
    
           ans = agent.run(task, verbose=verbose)
           report = self.evaluate(task, ans)
    
    
           if verbose:
               print("\n==============================")
               print("EVALUATION REPORT")
               print("==============================")
               print(json.dumps(report, indent=2))
               print("\n==============================")
               print("FINAL ANSWER")
               print("==============================")
               print(ans)
    
    
           for r in range(improve_rounds):
               if report["score"] >= 0.85:
                   break
               cfg = self.refine(cfg, report, task)
               agent = self.instantiate(cfg)
               if verbose:
                   print(f"\n\n==============================")
                   print(f"SELF-IMPROVEMENT ROUND {r+1}: UPDATED CONFIG")
                   print("==============================")
                   print(cfg.model_dump_json(indent=2))
               ans = agent.run(task, verbose=verbose)
               report = self.evaluate(task, ans)
               if verbose:
                   print("\nEVAL:", json.dumps(report, indent=2))
                   print("\nANSWER:\n", ans)
    
    
           return ans, cfg
    
    
    meta = MetaAgent()
    
    
    examples = [
       "Design an agent workflow to summarize a long meeting transcript and extract action items. Keep it concise.",
       "I have a local CSV at /content/sample.csv. Profile it and tell me the top 3 insights.",
       "Compute the monthly payment for a $12,000 loan at 8% APR over 36 months. Show the formula briefly.",
    ]
    
    
    print("\n==============================")
    print("RUNNING A QUICK DEMO TASK")
    print("==============================")
    demo_task = examples[2]
    _ = meta.build_and_run(demo_task, improve_rounds=1, verbose=True)



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticlePSX falls slightly in range-bound trading as KSE-100 loses 318 points
    Next Article South Africa workforce, stranded in India, to fly house from Wednesday
    Naveed Ahmad
    • Website
    • Tumblr

    Related Posts

    AI & Tech

    Medical health insurance startup Alan reaches €5B valuation

    March 11, 2026
    AI & Tech

    Fish Audio Releases Fish Audio S2: A New Generation of Expressive Text-to-Speech (TTS) with Absurdly Controllable Emotion

    March 11, 2026
    AI & Tech

    Google AI Introduces Gemini Embedding 2: A Multimodal Embedding Model that Lets Your Bring Text, Images, Video, Audio, and Docs into the Embedding Space

    March 11, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Demo
    Top Posts

    Plans for formidable six-nation movie enterprise introduced

    March 5, 20261 Views

    Mind Body Spirit Tree

    March 11, 20260 Views

    All Slay The Spire 2 Bosses

    March 11, 20260 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    Latest Reviews

    Subscribe to Updates

    Get the latest tech news from FooBar about tech, design and biz.

    Demo
    Most Popular

    Plans for formidable six-nation movie enterprise introduced

    March 5, 20261 Views

    Mind Body Spirit Tree

    March 11, 20260 Views

    All Slay The Spire 2 Bosses

    March 11, 20260 Views
    Our Picks

    Mind Body Spirit Tree

    March 11, 2026

    All Slay The Spire 2 Bosses

    March 11, 2026

    Tameer i Wattan Public School & College Abbottabad Jobs 2026 2026 Job Advertisement Pakistan

    March 11, 2026

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    Facebook X (Twitter) Instagram Pinterest
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    • Advertise
    • Disclaimer
    © 2026 TheNews92.com. All Rights Reserved. Unauthorized reproduction or redistribution of content is strictly prohibited.

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