Skip to content

feat: Multi-Objective Optimization #126

@lsm

Description

@lsm

Purpose

Enable NeoKai to make intelligent trade-offs between competing objectives like speed, quality, cost, and risk, rather than optimizing for a single metric. This is essential for AGI-level autonomy because:

  • Realistic decision making: Real-world tasks have competing constraints
  • User preference learning: Adapting to individual user priorities
  • Balanced outcomes: Finding Pareto-optimal solutions
  • Transparent trade-offs: Communicating decisions clearly

Without multi-objective optimization, NeoKai can't make intelligent trade-offs.


Current State

NeoKai has:

  • Single objective: complete the task
  • No trade-off analysis
  • No user preference learning
  • No multi-criteria decision making

Each task is approached with the same priorities regardless of context.


Proposed Approach

Phase 1: Objective Framework

  1. Objective Definition

    interface Objective {
      id: string;
      name: string;
      description: string;
      
      // Measurement
      metric: Metric;
      direction: 'minimize' | 'maximize';
      unit: string;
      
      // Constraints
      minimum?: number;  // Hard floor
      maximum?: number;  // Hard ceiling
      target?: number;   // Soft target
      
      // Priority
      weight: number;    // Relative importance
      priority: 'critical' | 'high' | 'medium' | 'low';
    }
  2. Built-in Objectives

    const builtInObjectives = {
      quality: {
        name: 'Quality',
        metric: 'correctness_score',
        direction: 'maximize',
        weight: 1.0,
        priority: 'high'
      },
      
      speed: {
        name: 'Speed',
        metric: 'completion_time',
        direction: 'minimize',
        weight: 0.7,
        priority: 'medium'
      },
      
      cost: {
        name: 'Cost',
        metric: 'token_cost',
        direction: 'minimize',
        weight: 0.5,
        priority: 'medium'
      },
      
      risk: {
        name: 'Risk',
        metric: 'risk_score',
        direction: 'minimize',
        weight: 0.8,
        priority: 'high'
      },
      
      maintainability: {
        name: 'Maintainability',
        metric: 'complexity_score',
        direction: 'minimize',
        weight: 0.6,
        priority: 'medium'
      },
      
      userSatisfaction: {
        name: 'User Satisfaction',
        metric: 'expected_satisfaction',
        direction: 'maximize',
        weight: 1.0,
        priority: 'critical'
      }
    };

Phase 2: Trade-off Analysis Engine

  1. Pareto Optimization

    interface ParetoOptimizer {
      // Find Pareto-optimal solutions
      optimize(
        alternatives: Alternative[],
        objectives: Objective[]
      ): Promise<ParetoFrontier>;
      
      // Score alternative across objectives
      scoreAlternative(
        alternative: Alternative,
        objectives: Objective[]
      ): Promise<ObjectiveScores>;
    }
    
    interface ParetoFrontier {
      optimalAlternatives: Alternative[];
      dominatedAlternatives: Alternative[];
      tradeOffs: TradeOff[];
    }
    
    interface TradeOff {
      fromAlternative: string;
      toAlternative: string;
      gains: ObjectiveChange[];
      losses: ObjectiveChange[];
    }
  2. Alternative Generation

    interface AlternativeGenerator {
      // Generate alternative approaches
      generate(task: Task): Promise<Alternative[]>;
    }
    
    interface Alternative {
      id: string;
      description: string;
      estimatedScores: Map<string, number>;  // objective -> score
      approach: string;
      risks: string[];
      dependencies: string[];
    }
  3. Trade-off Visualization

    interface TradeOffPresenter {
      // Present trade-offs to user
      present(frontier: ParetoFrontier): TradeOffDisplay;
    }
    
    // Example display:
    const exampleDisplay = `
    Found 3 Pareto-optimal approaches:
    
    Option A: Quick Fix
    - Quality: 70% (faster but less thorough)
    - Speed: 30 min (fastest)
    - Cost: $0.50 (cheapest)
    - Risk: Medium (might need follow-up)
    
    Option B: Thorough Solution  [RECOMMENDED]
    - Quality: 95% (comprehensive)
    - Speed: 2 hours (moderate)
    - Cost: $2.00 (moderate)
    - Risk: Low (unlikely to need changes)
    
    Option C: Over-engineered
    - Quality: 99% (excessive for this task)
    - Speed: 6 hours (slowest)
    - Cost: $5.00 (most expensive)
    - Risk: Very Low (but diminishing returns)
    `;

Phase 3: User Preference Learning

  1. Preference Model

    interface UserPreferences {
      // Learned preferences
      objectives: Map<string, ObjectivePreference>;
      
      // Context-specific preferences
      contextOverrides: Map<string, ContextPreference>;
    }
    
    interface ObjectivePreference {
      objectiveId: string;
      weight: number;
      confidence: number;
      
      // How this was learned
      source: 'explicit' | 'inferred' | 'default';
      examples: PreferenceExample[];
    }
  2. Preference Learning

    interface PreferenceLearner {
      // Learn from explicit feedback
      learnExplicit(feedback: UserFeedback): void;
      
      // Learn from implicit signals
      learnImplicit(behavior: UserBehavior): void;
      
      // Get current preferences
      getPreferences(): UserPreferences;
    }
    
    // Implicit signals:
    const implicitSignals = {
      // User frequently asks for faster solutions
      prefersSpeed: {
        signals: ['rushed_timeline', 'asap_requests'],
        weightAdjustment: +0.2
      },
      
      // User frequently corrects quality issues
      prefersQuality: {
        signals: ['quality_corrections', 'thorough_review_requests'],
        weightAdjustment: +0.3
      },
      
      // User frequently rejects expensive solutions
      prefersLowCost: {
        signals: ['cost_concerns', 'budget_mentions'],
        weightAdjustment: +0.2
      }
    };
  3. Preference Elicitation

    interface PreferenceElicitor {
      // Ask user about preferences
      elicit(): Promise<UserPreferences>;
      
      // Detect when preferences should be clarified
      shouldElicit(context: Context): boolean;
    }

Phase 4: Context-Sensitive Optimization

  1. Context Modifiers

    interface ContextModifier {
      // Adjust objectives based on context
      modify(
        objectives: Objective[],
        context: Context
      ): Objective[];
    }
    
    const contextModifiers = {
      productionDeployment: {
        quality: { weight: 1.5 },  // Much more important
        speed: { weight: 0.5 },    // Less important
        risk: { weight: 2.0 }      // Critical
      },
      
      prototype: {
        quality: { weight: 0.7 },  // Less important
        speed: { weight: 1.5 },    // Much more important
        cost: { weight: 0.8 }
      },
      
      securityRelated: {
        risk: { weight: 3.0 },     // Critical
        quality: { weight: 1.5 }
      },
      
      userDemo: {
        speed: { weight: 1.5 },
        quality: { weight: 1.2 },
        maintainability: { weight: 0.5 }  // Less important
      }
    };
  2. Context Detection

    interface ContextDetector {
      // Detect current context
      detect(task: Task): Promise<TaskContext>;
    }
    
    interface TaskContext {
      primaryContext: string;
      secondaryContexts: string[];
      confidence: number;
    }

Phase 5: Negotiation & Communication

  1. Trade-off Communication

    interface TradeOffCommunicator {
      // Explain trade-offs to user
      explain(decision: OptimizationDecision): string;
      
      // Negotiate with user
      negotiate(
        current: Alternative,
        userRequest: string
      ): Promise<Alternative>;
    }
    
    // Example explanation:
    const exampleExplanation = `
    I've selected Option B (Thorough Solution) because:
    
    - It best matches your preference for quality (weight: 1.0)
    - The moderate time investment (2 hrs) is acceptable given your typical timeline flexibility
    - The low risk profile aligns with your risk-averse preference
    - Cost is reasonable at $2.00
    
    If you'd prefer a faster solution, Option A would save 1.5 hours but with 25% lower quality and medium risk. Would you like me to switch?
    `;
  2. Constraint Negotiation

    interface ConstraintNegotiator {
      // When constraints conflict, negotiate resolution
      negotiate(
        constraints: Constraint[]
      ): Promise<Resolution>;
    }
    
    // Example:
    // "You want this done in 1 hour AND with 99% quality. 
    //  I can do 90% quality in 1 hour, or 99% quality in 3 hours.
    //  Which would you prefer?"

Phase 6: Decision Framework

  1. Decision Process

    interface OptimizationDecision {
      selectedAlternative: Alternative;
      objectives: Objective[];
      userPreferences: UserPreferences;
      context: TaskContext;
      reasoning: string;
      alternativesConsidered: Alternative[];
    }
    
    interface DecisionMaker {
      // Make optimized decision
      decide(
        task: Task,
        alternatives: Alternative[],
        objectives: Objective[],
        preferences: UserPreferences,
        context: TaskContext
      ): Promise<OptimizationDecision>;
    }
  2. Decision Review

    interface DecisionReviewer {
      // Review past decisions for learning
      review(decision: OptimizationDecision, outcome: Outcome): void;
      
      // Identify patterns in decision quality
      analyzePatterns(): DecisionPattern[];
    }

Technical Considerations

Optimization Complexity

  • Handling many objectives efficiently
  • Avoiding analysis paralysis
  • Scalability of alternative generation

Preference Accuracy

  • Learning preferences reliably
  • Handling conflicting signals
  • Updating preferences over time

Communication Clarity

  • Making trade-offs understandable
  • Avoiding information overload
  • Supporting user decision making

Fairness & Bias

  • Avoiding bias in objective weighting
  • Treating user preferences fairly
  • Handling edge cases equitably

Success Metrics

  1. Decision Quality: User satisfaction with decisions
  2. Preference Accuracy: Correlation between learned and actual preferences
  3. Efficiency: Time to make decisions
  4. Trade-off Clarity: User understanding of trade-offs

Implementation Roadmap

  1. Phase 1: Basic objective framework
  2. Phase 2: Pareto optimization engine
  3. Phase 3: User preference learning
  4. Phase 4: Context-sensitive optimization
  5. Phase 5: Negotiation and communication
  6. Phase 6: Decision framework integration

Questions for Discussion

  1. What should default objective weights be?
  2. How to handle users with very different preferences?
  3. Should preferences be per-project or per-user?
  4. How often should preferences be recalibrated?

Part of the AGI-Level Autonomy initiative

Metadata

Metadata

Assignees

No one assigned

    Labels

    agi-foundationCore components for AGI-level autonomyenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions