synth_ai.sdk.optimization.job
Job lifecycle utilities for optimization jobs.
This module provides utilities for tracking and emitting job lifecycle events
using the OpenResponses-aligned event schema. It can be used by SDK clients
to construct canonical events and track job state.
Example:
Classes
JobStatus
Job lifecycle status values.
Methods:
from_string
is_terminal
is_success
JobLifecycle
Track and emit job lifecycle events.
This class provides a stateful wrapper around job lifecycle, making it easy
to emit canonical events and track status transitions. It maintains an
event history that can be used for debugging or persistence.
Attributes:
job_id: The unique job identifierstatus: Current job statusevents: History of emitted eventsstarted_at: Timestamp when job started (set on first start())ended_at: Timestamp when job ended (set on complete/fail/cancel)
start
data: Optional event data (e.g., config info)message: Optional human-readable message
- The job.in_progress event dictionary
ValueError: If job is not in PENDING status
complete
data: Optional event data (e.g., results, best_score)message: Optional human-readable message
- The job.completed event dictionary
ValueError: If job is not in IN_PROGRESS status
fail
error: Error message or descriptiondata: Optional event data (e.g., traceback, error details)message: Optional human-readable message
- The job.failed event dictionary
ValueError: If job is not in IN_PROGRESS status
cancel
reason: Cancellation reasondata: Optional event datamessage: Optional human-readable message
- The job.cancelled event dictionary
ValueError: If job is already in a terminal status
add_candidate
candidate_id: Unique identifier for the candidatedata: Optional event data (e.g., candidate config)message: Optional human-readable message
- The candidate.added event dictionary
complete_candidate
candidate_id: Unique identifier for the candidatescore: Optional evaluation scoredata: Optional event data (e.g., metrics, evaluation results)message: Optional human-readable message
- The candidate.completed event dictionary