Skip to main content

enterprise_ai.heartbeat

Source: sdks/python/src/enterprise_ai/heartbeat/__init__.py. Back to the Python SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Model HeartbeatResponse​

Parsed answer of POST /v1/runs/{id}/heartbeat (shared runtime semantics).

Fields:

NameTypeRequiredDescription
run_idstr | NonenoIdentifier of the run named in the answer.
statestr | NonenoState of the run, from the state or status field of the answer.
agent_statusstr | NonenoStatus of the agent reported by the server (for example suspended or killed).
actionstrnoAction asked by the server, in lower case (default continue); becomes stop when the status asks to stop.
reasonstr | NonenoWhy the action is taken. Written to the audit trail with the actor and the time.
rawdict[str, Any]noRaw answer as a dict.

Attributes:

NameTypeRequiredDescription
stopboolyesTrue when action is stop, kill, cancel or suspend.

HeartbeatResponse.parse​

parse(answer: Any) -> HeartbeatResponse

Build a response from a heartbeat answer; an answer that is not a dict gives the default response.

NameTypeDefaultRequiredDescription
answerAnyyesRaw answer of POST /v1/runs/{id}/heartbeat.

Returns: HeartbeatResponse. A HeartbeatResponse: Parsed answer of POST /v1/runs/{id}/heartbeat (shared runtime semantics).

Class Heartbeat​

Background heartbeat for a sync run (context manager).

Attributes:

NameTypeRequiredDescription
beatsyesNumber of heartbeats answered by the server.
errorsyesNumber of heartbeats that failed with an EaiError.
intervalyesSeconds between two heartbeats.
last_answerAnyyesRaw answer of the last successful heartbeat, or None.
last_responseHeartbeatResponse | NoneyesLast answer parsed as a HeartbeatResponse, or None before the first one.
on_stopyesFunction called with the raw answer when the server asks to stop, or None.
reasonstr | NoneyesWhy the action is taken. Written to the audit trail with the actor and the time.
run_idyesIdentifier of the run that receives the heartbeats.
runsyesRuns client used to post the heartbeats.
stateyesFunction that returns the fields of the next heartbeat.
stop_eventyesthreading.Event set when the server asks the run to stop.
stop_requestedboolyesTrue once the server asked this run to stop.

Constructor Heartbeat​

Heartbeat(runs: Any, run_id: str, interval: float = 15.0, state: Callable[[], dict[str, Any]] | None = None, stop_event: threading.Event | None = None, on_stop: Callable[[dict[str, Any]], None] | None = None) -> None

Prepare the heartbeat of a run; the background thread starts with start() or on with entry.

NameTypeDefaultRequiredDescription
runsAnyyesRuns client whose heartbeat(run_id, ...) posts /v1/runs/{id}/heartbeat.
run_idstryesIdentifier of the run that receives the heartbeats.
intervalfloat15.0noSeconds between two heartbeats (default 15.0).
stateCallable[[], dict[str, Any]] | NoneNonenoFunction called before each beat that returns the heartbeat fields (step, message, progress, worker); empty by default.
stop_eventthreading.Event | NoneNonenothreading.Event to set when the server asks to stop, usually the stop_event of the agent loop; a new one by default.
on_stopCallable[[dict[str, Any]], None] | NoneNonenoFunction called with the raw answer when the server asks the run to stop.

Heartbeat.beat​

beat() -> Any

Send one heartbeat now; sets stop_event when the server asks to stop.

This element takes no parameter.

Returns: Any. Raw answer of the server, or None when the call raised an EaiError (counted in errors).

Heartbeat.start​

start() -> Heartbeat

Start the background thread that beats every interval seconds until stop() or a stop request; does nothing when it already runs.

This element takes no parameter.

Returns: Heartbeat. A Heartbeat: Background heartbeat for a sync run (context manager).

Heartbeat.stop​

stop() -> None

Stop the background thread and wait for it at most interval + 1 seconds.

This element takes no parameter.

Returns: None.

Class AsyncHeartbeat​

Heartbeat as an asyncio task for the async client (async with).

Attributes:

NameTypeRequiredDescription
beatsyesNumber of heartbeats answered by the server.
intervalyesSeconds between two heartbeats.
run_idyesIdentifier of the run that receives the heartbeats.
runsyesAsync runs client used to post the heartbeats.
stateyesFunction that returns the fields of the next heartbeat.
stop_eventasyncio.Eventyesasyncio.Event set when the server asks the run to stop; it also ends the heartbeat task.

Constructor AsyncHeartbeat​

AsyncHeartbeat(runs: Any, run_id: str, interval: float = 15.0, state: Callable[[], dict[str, Any]] | None = None) -> None

Prepare the heartbeat of a run; the asyncio task starts on async with entry and is cancelled on exit.

NameTypeDefaultRequiredDescription
runsAnyyesAsync runs client whose heartbeat(run_id, ...) posts /v1/runs/{id}/heartbeat.
run_idstryesIdentifier of the run that receives the heartbeats.
intervalfloat15.0noSeconds between two heartbeats (default 15.0).
stateCallable[[], dict[str, Any]] | NoneNonenoFunction called before each beat that returns the heartbeat fields (step, message, progress, worker); empty by default.

AsyncHeartbeat.beat​

async beat() -> Any

Send one heartbeat now; sets stop_event when the answer asks the agent to stop.

This element takes no parameter.

Returns: Any. Answer of the server, or None when the call raised an EaiError.

Functions​

should_stop​

should_stop(answer: Any) -> bool

True when a heartbeat answer asks the agent to stop.

NameTypeDefaultRequiredDescription
answerAnyyesHeartbeat answer, as a dict or a HeartbeatResponse.

Returns: bool. True when the action is stop, kill, cancel or suspend, when the run or agent status is terminal (cancelled, killed, suspended, failed) or when stop is true.