/** * The hierarchical manager loop: `AgentTeam({ process: 'hierarchical', managerLlm })`. * * Python parity: `praisonaiagents/process/process.py::Process.hierarchical`. A * synthetic "Manager" agent, running on `manager_llm`, is shown the status of * every real task and answers with `{task_id, agent_name, action}`. The team * executes what it names, re-prompts on an invalid pick, and stops on * `action: "stop"`, on max iterations, or when every task is accounted for. * * The bounds are Python's, and they exist because each one was a hang: a task * that ends "failed" is a valid id that never becomes "completed", so without * the per-task re-selection cap the manager can re-delegate it forever. */ import type { TeamTaskStatus } from './team-options'; /** What the manager is told about one task. */ export interface ManagerTaskView { task_id: number; name: string; description: string; status: TeamTaskStatus; agent: string; } /** The manager's answer. Python parity: ManagerInstructions. */ export interface ManagerInstructions { task_id: number; agent_name: string; action: string; } /** JSON schema pinned on the manager's reply. Python parity: output_pydantic=ManagerInstructions. */ export declare const MANAGER_INSTRUCTIONS_SCHEMA: { readonly type: "object"; readonly properties: { readonly task_id: { readonly type: "integer"; }; readonly agent_name: { readonly type: "string"; }; readonly action: { readonly type: "string"; readonly enum: readonly ["execute", "stop"]; }; }; readonly required: readonly ["task_id", "agent_name", "action"]; readonly additionalProperties: false; }; /** Everything the loop needs from the team, so this module never touches team state directly. */ export interface HierarchicalOptions { /** Model the Manager agent runs on. Python parity: manager_llm. */ managerLlm: string; /** Iteration ceiling. Python parity: max_iter. */ maxIter: number; verbose: boolean; /** A fresh view of every delegable task, read once per iteration. */ snapshot: () => ManagerTaskView[]; /** Names of the agents the manager may delegate to. */ agentNames: string[]; /** Point a task at a different agent, by the name the manager chose. */ assignAgent: (taskId: number, agentName: string) => void; /** Run one task and leave its status updated. */ runTask: (taskId: number) => Promise; /** * Ask the manager. Defaults to a "Manager" Agent on `managerLlm`; injectable * so a caller (or a test) can supply the decision without a model. */ ask?: (prompt: string) => Promise; } /** Why the loop stopped. Useful to callers and to tests. */ export type HierarchicalOutcome = 'completed' | 'stopped' | 'max-iterations' | 'invalid-selections' | 'manager-error'; /** Pull the manager's JSON out of a reply that may be fenced or padded with prose. */ export declare function parseManagerInstructions(reply: string): ManagerInstructions | null; /** * Run the tasks under manager supervision. Returns why the loop ended; task * results are left on the team through the `runTask` callback. */ export declare function runHierarchical(options: HierarchicalOptions): Promise;