import type { BrainArbiter, BrainDecision, BrainDecisionOption, BrainDecisionRequest, BrainDecisionSource, BrainRisk } from './brain.js'; import type { DecisionNode, GoalNode, FactNode, ChangeNode } from './knowledge-graph.js'; import type { KnowledgeGraph } from './knowledge-graph.js'; import type { FleetBus } from './fleet-bus.js'; export type { BrainRisk }; export type AutonomousDecisionType = 'spawn' | 'approve_change' | 'reject_change' | 'prioritize_goals' | 'escalate_task' | 'rollback_change' | 'retry_task' | 'merge_results' | 'decompose_goal' | 'assign_task'; export interface AutonomousDecisionRequest { id: string; source: BrainDecisionSource; decisionType: AutonomousDecisionType; question: string; context: { /** Relevant facts from the knowledge graph */ facts?: FactNode[]; /** Goals relevant to this decision */ goals?: GoalNode[]; /** Change being reviewed (for approval decisions) */ change?: ChangeNode; /** Current fleet status */ fleetStatus?: { running: number; idle: number; total: number; costSoFar: number; }; /** Task that triggered this decision */ taskDescription?: string; /** Error that triggered escalation, if any */ error?: string; /** Number of times this task has been attempted */ attempts?: number; }; options: BrainDecisionOption[]; risk: BrainRisk; /** Whether this decision requires consensus */ requiresConsensus: boolean; } export interface SpawnDecision { role: string; budget: { timeoutMs?: number; maxIterations?: number; maxToolCalls?: number; maxCostUsd?: number; }; rationale: string; } export interface ApprovalDecision { approved: boolean; rationale: string; waivers?: string[]; conditions?: string[]; } export interface PrioritizationDecision { orderedGoals: string[]; rationale: string; } export interface EscalationDecision { action: 'retry' | 'delegate' | 'mark_failed' | 'ask_for_help'; rationale: string; budgetAdjustment?: { increaseFactor?: number; newTimeoutMs?: number; addModel?: string; }; } export interface AutonomousBrainOptions { /** The LLM provider for making decisions */ llmProvider: LLMProvider; graph: KnowledgeGraph; fleet?: FleetBus | undefined; /** Maximum retries before a task is marked failed. Default: 3. */ maxRetries?: number | undefined; /** Risk threshold above which consensus is required. Default: 'high'. */ consensusRiskThreshold?: BrainRisk | undefined; /** Self-improve: track decision history for learning. Default: true. */ selfImprove?: boolean | undefined; } export interface LLMProvider { /** * Generate a decision. Receives the full context as a structured prompt. * Returns the chosen option id and rationale. */ decide(prompt: DecisionPrompt): Promise<{ optionId: string; rationale: string; }>; } export interface DecisionPrompt { decisionType: AutonomousDecisionType; question: string; context: string; options: BrainDecisionOption[]; risk: BrainRisk; decisionHistory: DecisionNode[]; /** Hints derived from self-improvement data */ selfImproveHints?: string[]; } export declare class AutonomousBrain implements BrainArbiter { private readonly graph; private readonly fleetBus?; private readonly llmProvider; private readonly maxRetries; private readonly consensusRiskThreshold; private readonly selfImprove; /** Tracks failure patterns for self-improvement. */ private failurePatterns; private readonly RISK_ORDER; private _emit; constructor(opts: AutonomousBrainOptions); /** Implements BrainArbiter — bridges standard brain.ts interface to autonomous engine. */ decide(request: BrainDecisionRequest): Promise; /** * Primary autonomous decision engine — receives AutonomousDecisionRequest, * queries the LLM, records the decision, and returns a BrainDecision. * * Specialized methods (decideSpawn, decideApproval, etc.) should call this * directly with a pre-built AutonomousDecisionRequest. */ decideAuto(request: AutonomousDecisionRequest): Promise; /** * Decide whether to spawn a subagent, which role to use, and what budget. */ decideSpawn(source: BrainDecisionSource, taskDescription: string, availableFacts: FactNode[], fleetStatus: { running: number; idle: number; total: number; costSoFar: number; }): Promise; /** * Decide whether to approve a proposed change. */ decideApproval(source: BrainDecisionSource, change: ChangeNode, relevantFacts: FactNode[]): Promise; /** * Decide how to handle a failed task. */ decideEscalation(source: BrainDecisionSource, taskId: string, error: string, attempts: number): Promise; /** * Record the outcome of a decision for self-improvement. * Call this after a spawned agent completes or a change is applied. */ recordOutcome(decisionId: string, outcome: 'success' | 'failure', _detail?: string): void; private _getSelfImproveHints; private _toAutonomous; private _inferDecisionType; private _serializeContext; private _loadHistory; private _recordDecision; private _inferRoles; private _changeRisk; } //# sourceMappingURL=autonomous-brain.d.ts.map