Skip to main content

Function Signature

Description

The main entry point for running a discovery process. This function accepts file paths or inline strings for the initial program and evaluator, wires up configuration, and returns a DiscoveryResult containing the best solution found.

Parameters

Union[str, Path, Callable]
required
File path or callable function (program_path) -> metrics_dict that evaluates program performance.
  • File path: Path to a Python script that defines an evaluate() function
  • Callable: Python function that accepts a program path and returns a metrics dictionary
Optional[Union[str, Path, List[str]]]
Starting solution for the discovery process. Can be:
  • File path: Path to a file containing the initial program
  • Inline string: Source code as a string
  • List of strings: Source code split into lines
  • None: LLM generates a solution from scratch
Default: None
Optional[str]
Model name(s), comma-separated. Overrides config file settings.Examples:
  • "gpt-5"
  • "gpt-5,gemini/gemini-3-pro"
Default: None (uses config file)
Optional[int]
Maximum number of iterations to run. Overrides config.max_iterations.Default: None (uses config file)
Search algorithm name. Overrides config file settings.Native algorithms:
  • "adaevolve" - Adaptive multi-island evolutionary search
  • "evox" - Self-evolving optimization
  • "topk" - Top-K selection
  • "beam_search" - Beam search with diversity
  • "best_of_n" - Generate N variants per iteration
  • "openevolve_native" - MAP-Elites + island-based search
  • "gepa_native" - Pareto-efficient search with reflective prompting
External backends (require --extra external):
  • "openevolve" - OpenEvolve backend
  • "gepa" - GEPA backend
  • "shinkaevolve" - ShinkaEvolve backend
Default: None (uses config file)
Union[str, Path, Config, None]
Configuration for the discovery process.
  • YAML path: Path to a YAML configuration file
  • Config object: Pre-built Config instance
  • None: Use default configuration
Default: None
bool
Enable agentic mode. The codebase root is automatically derived from initial_program.Default: False
Optional[str]
Directory where results, logs, and checkpoints are written. If None, a temporary directory is created.Default: None
Optional[str]
Domain-specific context provided to the LLM for better solution generation.Default: None
Optional[str]
Base URL for an OpenAI-compatible API endpoint.Default: None
bool
Remove temporary files after the run completes.Default: True

Returns

DiscoveryResult
Result object containing:

Examples

Basic Usage with File Paths

Using a Callable Evaluator

Inline String Program

Starting from Scratch (No Initial Program)

Using Custom Configuration

Multiple Models

Agentic Mode

Error Handling

Missing Model Configuration

Missing External Package

Invalid Evaluator

Notes

  • The function runs asynchronously internally but presents a synchronous interface
  • Results are automatically checkpointed during the run
  • Use cleanup=False to preserve temporary files and intermediate results
  • The output_dir will contain:
    • best/ - Best program found
    • checkpoints/ - Periodic checkpoints
    • logs/ - Execution logs
  • Initial program is optional; the LLM can generate solutions from scratch with a good system_prompt

See Also