STATEK
API Reference
Jobs

Jobs

Jobs are durable execution units. JobDef stores the reusable definition; Job stores mutable execution state, history, locals, usage, errors, and continuation fields.

SymbolImport pathPurposeStability
JobDefstatek.executors.jobDefines agent, metadata, warmup, prompt params, chat style, localeCore
Jobstatek.executors.jobDurable execution stateCore
JobStatusstatek.executors.jobLifecycle enumCore
JobDefErrorstatek.executors.jobStored job-definition errorCore

JobStatus

JobStatus.READY
JobStatus.WARMING_UP
JobStatus.STARTED
JobStatus.SUSPENDED
JobStatus.DONE

Use JobStatus to query and tag jobs in dbzero.

JobDef

@db0.memo
@dataclass
class JobDef:
    agent: Agent
    metadata: Optional[dict[str, str]] = None
    job_params: Optional[dict[str, Any]] = None
    warmup_code: str | CodeBlock | Sequence[str | CodeBlock] | None = None
    _chat_style: Optional[ChatStyle] = None
    locale: Optional[StatekLocale] = None

Freezes the configuration used to create and run jobs.

Import path: from statek.executors.job import JobDef

Parameters

NameDescription
agentAgent assigned to the job. The object is tagged with this agent.
metadataJob metadata. If omitted, agent metadata is copied. MODEL is required.
job_paramsValues passed into prompt formatting.
warmup_codeOptional Python code executed before the first LLM request.
_chat_styleOptional job-level ChatStyle override.
localeOptional StatekLocale for language-specific behavior.

Properties and methods

MemberReturnsDescription
model`strNone`
model_family`strNone`
provider`strNone`
chat_style`ChatStyleNone`
set_error(error, collect_traceback=True)NoneStores a JobDefError tagged to this definition.
get_errors()Iterable[JobDefError]Yields stored definition errors.
has_errors()boolReturns whether errors exist.
clear_errors()NoneRemoves stored definition errors.
update_warmup_code(warmup_code)NoneParses and replaces warmup only when changed.
set_chat_style(chat_style)NoneSets or clears the job chat-style override.

Raises

JobDef(...) raises ValueError when no MODEL metadata is available.

from statek.executors.job import JobDef
 
job_def = JobDef(
    agent=agent,
    metadata={"MODEL": "openai/gpt-5-mini"},
    warmup_code='print("ready")',
)

Job

@db0.memo
class Job:
    def __init__(
        self,
        job_def: JobDef,
        job_status: JobStatus = JobStatus.READY,
        py_env: PyEnv = None,
        chat_log: list[str | ChatLogItem | UserLogItem] = None,
        awaited_result: FutureResult | None = None,
        next_instr_num: int | None = None,
        warmup_block_num: int | None = None,
        error: JobDefError | None = None,
        created_at: datetime | None = None,
        parent_job: Job | None = None,
        model_family: str | None = None,
        model: str | None = None,
    )

Represents one durable unit of work and its persisted Python environment.

Import path: from statek.executors.job import Job

Important attributes

AttributeDescription
job_defThe immutable job definition.
parent_jobParent job for subtasks, if any.
py_envPython locals, console output, and exit status.
chat_logStored warmup, user, assistant, tool, and notification history.
awaited_resultFuture that suspended the job, when status is SUSPENDED.
next_instr_numContinuation instruction index after suspension.
warmup_block_numCurrent warmup block index.
errorStored job error, if terminated by an error path.
created_atCreation timestamp.
usageAccumulated LLM usage. See STATEK Metering for fields and cost resolution.
num_completionsCount of completed units observed when a DONE job is reactivated.

Common properties and methods

MemberReturnsDescription
statusJobStatusCurrent lifecycle status.
model`strNone`
model_family`strNone`
system_prompt(difficulty=None)strFormats the agent prompt for this job.
find_locals(var_type=None, var_name=None, ext_scan=True)Iterable[Any]Searches Python locals and persistent context.
add_locals(**kwargs)NoneInjects values into the Python local state.
find_sub_task_handler(id=None)`SubTaskHandlerNone`
push_notification(handler)NoneAdds a completed subtask notification.
add_ext_ref(obj)NoneTracks an external memo reference.
contains_ext_ref(obj)boolChecks an external memo reference.
add_error_handler(error_handler, context)NoneRegisters a handler for job termination errors.
add_error_handlers_from(parent_job)NoneCopies handlers from a parent job.
notify_handlers(error=None)NoneInvokes and clears registered handlers.
tokens_per_sec()floatApproximate provider-token throughput from recorded job history and response timing.
approx_token_usageintByte-based harness estimate: (total_bytes_sent + total_bytes_received) // 4.

See Error Handling for the cleanup pattern and handler caveats.

Raises

push_notification(...) raises RuntimeError if the handler has not completed. find_sub_task_handler(id=...) raises RuntimeError when a specific id has not completed.

from statek.executors.job import Job, JobStatus
 
job = Job(job_def=job_def, job_status=JobStatus.READY)
job.add_locals(customer_id="C-123")
 
print(job.status)
print(job.py_env.local_state["customer_id"])

Related APIs: Runners, Subtasks, Context.