Overview
TheHypothesisGenerator analyzes experiment results and generates ranked, testable hypotheses to guide the next iteration of the experiment loop. It balances exploration and exploitation strategies and provides confidence scores for each hypothesis.
Key Features
- Generates 2-3 ranked, testable hypotheses from analysis results
- Balances exploration (new approaches) vs exploitation (refining what works)
- Provides confidence scores (0.0-1.0) and priorities (1-3)
- Suggests concrete model choices and hyperparameters
- Maintains conversation context for Thought Signature continuity
- Intelligent fallback when Gemini is unavailable
Class Definition
Constructor
Shared
GeminiClient instance for API calls. Sharing the same client across cognitive components preserves conversation history.Methods
generate
Generate hypotheses for the next experiment iteration.Parameters
Analysis result from the most recent experiment, containing:
experiment_name(str): Name of analyzed experimentiteration(int): Iteration numbersuccess(bool): Whether experiment succeededprimary_metric(Optional[MetricComparison]): Metric comparison datatrend_pattern(TrendPattern): Detected performance trendkey_observations(list[str]): Actionable insightsreasoning(str): Analysis reasoning
Current experiment state containing:
experiments(list[ExperimentResult]): Historical resultsconfig(Config): Configuration including task type, constraints, max iterationscurrent_iteration(int): Current iteration numberiterations_without_improvement(int): Plateau counter
Returns
Set of ranked hypotheses containing:
iteration(int): Iteration number these hypotheses are foranalysis_summary(str): Brief summary of what the analysis tells ushypotheses(list[Hypothesis]): 2-3 ranked hypotheses (see below)exploration_vs_exploitation(str): Strategy -"explore","exploit", or"balanced"reasoning(str): Overall reasoning for these hypotheses
get_generation_count
Get the number of hypothesis generations performed.Returns
Total number of hypothesis sets generated by this instance.
Data Structures
Hypothesis
A single testable hypothesis with suggested implementation.Unique identifier for the hypothesis (e.g., “h1”, “h2”).
Clear, testable hypothesis statement describing what to test.
Explanation of why this hypothesis is worth testing based on the analysis.
Recommended model class name (e.g., “RandomForestRegressor”).
Recommended hyperparameters for the suggested model.
Confidence in this hypothesis (0.0-1.0):
- 0.8-1.0: Strong evidence supports this direction
- 0.5-0.7: Moderate evidence, reasonable next step
- 0.2-0.4: Speculative but potentially high-value
Priority ranking (1-3):
- 1: Highest priority - implement this first
- 2: Secondary option
- 3: Exploratory/backup option
HypothesisSet
Exploration vs Exploitation Strategy
The generator automatically selects a strategy based on the analysis:Explore
Try fundamentally different approaches when:- Performance has plateaued for multiple iterations
- Current iteration is > 70% of max_iterations
- Trend pattern indicates a local optimum
Exploit
Refine promising approaches when:- Trend pattern shows consistent improvement
- Early iterations (≤5) with positive results
- Recent experiments show clear winning direction
Balanced
Mix both strategies (default) for:- Normal iteration flow
- Mixed results across iterations
- Moderate performance improvements
Confidence Scoring Guidelines
| Range | Interpretation | Example |
|---|---|---|
| 0.8-1.0 | Strong evidence from multiple iterations | ”XGBoost improved RMSE by 15% in last 2 trials” |
| 0.5-0.7 | Moderate evidence, reasonable step | ”Gradient boosting hasn’t been tried yet” |
| 0.2-0.4 | Speculative, potentially high-value | ”Neural network might capture non-linearities” |
System Prompt
The generator uses a comprehensive system prompt that guides Gemini to:- Generate 2-3 ranked hypotheses based on analysis
- Make each hypothesis specific and testable in a single experiment
- Balance exploration and exploitation
- Reference specific metric values and patterns
- Suggest concrete model choices and hyperparameters
- Include at least one “safe” refinement and one “exploratory” option
Usage Examples
Basic Hypothesis Generation
Selecting Top Hypothesis
Strategy-Based Selection
Integration with Full Pipeline
Handling Failed Experiments
Custom Hypothesis Filtering
Tracking Hypothesis History
Fallback Behavior
Integration Pattern
TheHypothesisGenerator fits between ResultsAnalyzer and ExperimentDesigner in the cognitive loop:
- Suggesting specific model types and parameters
- Indicating whether to explore or exploit
- Providing confidence-weighted options
- Connecting choices to observed patterns
See Also
- GeminiClient - Underlying API client
- ResultsAnalyzer - Generates input for hypothesis generation
- ExperimentDesigner - Consumes hypotheses for next design
- ReportGenerator - Uses hypothesis history in final reports