synth_ai.sdk.optimization.graph.job
Graph optimization job implementation.
This module provides the canonical GraphOptimizationJob class for running
graph/workflow optimization jobs.
Replaces: GraphOptimizationJob (from sdk/api/train), GraphEvolveJob (deprecated)
Backend endpoint: /api/graph-evolve/jobs, /api/graph_evolve/jobs
Algorithms:
- graph_gepa: Graph Genetic Evolutionary Prompt Algorithm (default, currently only)
from_config(): TOML config file (like old GraphOptimizationJob)from_dataset(): JSON dataset (like GraphEvolveJob)
Classes
Algorithm
Supported graph optimization algorithms.
Methods:
from_string
GraphOptimizationJobConfig
Configuration for a graph optimization job.
This dataclass holds all the configuration needed to submit and run
a graph optimization job.
Supports two modes:
- Config-based: Provide
config_pathpointing to a TOML file - Dataset-based: Internal use via from_dataset() constructor
backend_url: Base URL of the Synth API backend.api_key: Synth API key for authentication.config_path: Path to the TOML configuration file (config mode).config_dict: Dictionary configuration (programmatic mode).algorithm: Optimization algorithm to use.
GraphOptimizationJob
High-level SDK class for running graph optimization jobs.
This is the canonical class for graph optimization, unifying the old
GraphOptimizationJob (config-based) and GraphEvolveJob (dataset-based)
under a single API.
Two construction modes:
from_config(): Create from TOML config filefrom_dataset(): Create from JSON dataset (auto-generates task app)
job_id: The job ID (None until submitted)algorithm: The optimization algorithm being used
from_config
config_path: Path to TOML config filebackend_url: Backend API URL (defaults to env or production)api_key: API key (defaults to SYNTH_API_KEY env var)
- GraphOptimizationJob instance
ValueError: If required config is missingFileNotFoundError: If config file doesn’t exist
from_dict
config_dict: Configuration dictionarybackend_url: Backend API URL (defaults to env or production)api_key: API key (defaults to SYNTH_API_KEY env var)
- GraphOptimizationJob instance
from_dataset
dataset: Dataset as file path, dict, or GraphEvolveTaskSet objectpolicy_models: Model(s) to use for policy inferencerollout_budget: Total number of rollouts for optimizationproposer_effort: Proposer effort level (low, medium, high)judge_model: Override judge model from datasetjudge_provider: Override judge provider from datasetpopulation_size: Population size for GEPAnum_generations: Number of generations (auto-calculated if not specified)problem_spec: Detailed problem specification for the graph proposertarget_llm_calls: Target number of LLM calls for the graph (1-10)graph_type: Type of graph to train (“policy”, “verifier”, or “rlm”)initial_graph_id: Preset graph ID to optimize (required)backend_url: Backend API URL (defaults to env or production)api_key: API key (defaults to SYNTH_API_KEY env var)auto_start: Whether to start the job immediatelymetadata: Additional metadata for the job
- GraphOptimizationJob instance
from_job_id
job_id: Existing job IDbackend_url: Backend API URL (defaults to env or production)api_key: API key (defaults to SYNTH_API_KEY env var)
- GraphOptimizationJob instance for the existing job
job_id
algorithm
submit
- Job ID
RuntimeError: If job submission fails
get_status
- Job status dictionary
RuntimeError: If job hasn’t been submitted yet
poll_until_complete
timeout: Maximum seconds to wait for job completioninterval: Seconds between poll attemptsprogress: If True, print status updates during polling
- GraphOptimizationResult with typed status, best_score, etc.
RuntimeError: If job hasn’t been submitted yet
stream_until_complete
timeout: Maximum seconds to waitinterval: Seconds between status checks (for SSE reconnects)handlers: Optional StreamHandler instances for custom event handlingon_event: Optional callback called on each event
- GraphOptimizationResult with typed status, best_score, etc.
RuntimeError: If job hasn’t been submitted yet
cancel
reason: Optional reason for cancellation
- Dict with cancellation status
RuntimeError: If job hasn’t been submitted yet
download_graph_txt
- Graph export text
RuntimeError: If job hasn’t been submitted or delegate doesn’t support this
run_inference
input_data: Input data matching the task formatmodel: Override model (default: use job’s policy model)graph_snapshot_id: Specific GraphSnapshot to use (default: best)
- Output dictionary
RuntimeError: If job hasn’t been submitted or delegate doesn’t support this