Skip to content

Client and run handle

Async Python SDK for submitting and observing Zeroshot runs.

Client(*, target: Target | None = None, preset: Preset | None = None, runtime: _Runtime | None = None, environment: Mapping[str, str] | None = None, forward_github_token: bool = False)

Submit and observe Zeroshot graph runs and hosted stacks.

Parameters:

  • target (Target | None, default: None ) –

    Local target by default, an unauthenticated direct target, or a named hosted target.

  • preset (Preset | None, default: None ) –

    Default executable-owned graph preset. None selects software-change.

  • runtime (_Runtime | None, default: None ) –

    Default runtime. None requires a runtime on each string submission.

  • environment (Mapping[str, str] | None, default: None ) –

    Submission environment values. None reads the ambient environment; an explicit mapping replaces ambient credential variables. Native saved connections and local harness login still apply.

  • forward_github_token (bool, default: False ) –

    Send the submission environment's GH_TOKEN to a direct or hosted target. Without it, the target resolves GitHub access from its own stored connection and GH_TOKEN is not sent. Requires GH_TOKEN in the submission environment.

Raises:

The SDK never guesses a harness, provider, or model. Closing the client detaches observation and never stops runs.

__aenter__() -> Client async

Open the client and capture a default working folder.

Returns:

Raises:

__aexit__(exc_type: type[BaseException] | None, exc: BaseException | None, traceback: object) -> None async

Close client-owned routing state without stopping durable runs.

aclose() -> None async

Release client-owned routing state without stopping submitted runs.

run(task: str | RunRequest, **options: Unpack[_RunOptions]) -> RunResult async

run(task: str, **options: Unpack[_RunOptions]) -> RunResult
run(
    task: RunRequest, *, wait_timeout: float | None = None
) -> RunResult

Submit one graph run and wait for its terminal result.

Parameters:

  • task (str | RunRequest) –

    Task text for a built-in preset, or a complete RunRequest.

  • options (Unpack[_RunOptions], default: {} ) –

    Typed keyword options. title, preset, runtime, cwd, worktree, worktree_base, repository, source_connection, branch, revision, submission_key, workspace, workspace_placement, workspace_seeds, and copy_workspace apply to string submissions. worktree defaults to False; worktree_base accepts local or remote. See RunRequest for local-only worktree and cleanup semantics. wait_timeout is a non-negative observation deadline in seconds; omit it to wait indefinitely.

Returns:

  • RunResult –

    The terminal result. Graph failure remains data until raise_for_failure() is called.

Raises:

  • InvalidRequestError –

    If a string submission has no effective preset or runtime, or Zeroshot rejects the request.

  • RunWaitTimeout –

    If observation expires; its run attribute can resume waiting.

  • RunSuspendedError –

    If the attempt suspends; carries its run handle and status.

  • TargetError –

    If the sidecar or selected target is unavailable.

  • ProtocolError –

    If native output is malformed or incompatible.

Cancellation detaches observation and leaves the durable run active.

submit(task: str | RunRequest, **options: Unpack[_SubmitOptions]) -> Run async

submit(task: str, **options: Unpack[_SubmitOptions]) -> Run
submit(task: RunRequest) -> Run

Preflight in Zeroshot, submit one durable run, and return its handle.

Parameters:

  • task (str | RunRequest) –

    Task text for a built-in preset, or a complete RunRequest.

  • options (Unpack[_SubmitOptions], default: {} ) –

    Typed keyword options for string submissions: title, preset, runtime, cwd, worktree, worktree_base, repository, source_connection, branch, revision, submission_key, workspace, workspace_placement, workspace_seeds, and copy_workspace. worktree defaults to False; worktree_base accepts local or remote. See RunRequest for local-only worktree and cleanup semantics.

Returns:

  • Run –

    A durable run handle bound to this client's target.

Raises:

Exact RunRequest values cannot be combined with string-submission overrides. Preflight completes before local controller startup or direct-target contact.

submit_stack(request: StackRequest) -> Stack async

Validate and atomically submit one stack of runs to a hosted target.

Parameters:

  • request (StackRequest) –

    Immutable stack metadata, profile selector, delivery mode, and static run DAG.

Returns:

  • Stack –

    A durable stack handle bound to this client's hosted target.

Raises:

get_stack(stack_id: str) -> Stack

Reconstruct a durable hosted stack handle without target I/O.

Parameters:

  • stack_id (str) –

    Opaque server-assigned stack identity.

Returns:

  • Stack –

    A handle resolved lazily against this client's named hosted target.

Raises:

get_run(run_id: str, *, part_id: str | None = None) -> Run

Reconstruct a durable handle without target I/O.

Parameters:

  • run_id (str) –

    Stable public run identity. A saved part ID resolves on status lookup.

  • part_id (str | None, default: None ) –

    Select a single admitted part. Omit to follow the run across continuations.

Returns:

  • Run –

    A handle resolved lazily against this client's target.

Raises:

list_runs() -> tuple[RunSummary, ...] async

Return summaries for runs retained by this client's target.

stage_file(source: str | Path, *, operation: str | None = None, run_id: str | None = None) -> dict[str, JsonValue] async

Upload a private file or folder for a filepath input or answer.

Parameters:

  • source (str | Path) –

    Local path relative to the captured client workspace, independent of run cwd.

  • operation (str | None, default: None ) –

    Stable upload retry key; omit to generate one in the CLI.

  • run_id (str | None, default: None ) –

    Upload identity from a previous receipt, for an interrupted upload retry.

Returns:

  • dict[str, JsonValue] –

    The CLI staged receipt. Put this object directly in a declared filepath field.

  • dict[str, JsonValue] –

    Admission always copies accepted inputs, including for local in-place runs.

Raises:

Cancellation reaps the CLI child. Retry an uncertain upload with the same two identities.

upload_file(source: str | Path, path: str, *, scope: Literal['user', 'org'] = 'user', operation: str | None = None) -> dict[str, JsonValue] async

Replace a reusable library file or folder with the local source's current bytes.

Parameters:

  • source (str | Path) –

    Local path relative to the captured client workspace.

  • path (str) –

    Complete target-relative library name.

  • scope (Literal['user', 'org'], default: 'user' ) –

    User or organization library.

  • operation (str | None, default: None ) –

    Stable retry key; conflicting reuse is refused by the native store.

Returns:

  • dict[str, JsonValue] –

    The unchanged CLI replaced receipt, including its address and operation key.

list_files(path: str | None = None, *, scope: Literal['user', 'org'] | None = None, run_id: str | None = None, member: str | None = None) -> dict[str, JsonValue] async

List library/publication names, or the members of one selected file or folder.

Parameters:

  • path (str | None, default: None ) –

    Select one complete named tree; omit to list names.

  • scope (Literal['user', 'org'] | None, default: None ) –

    Library scope, defaulting to user. Cannot be combined with run_id.

  • run_id (str | None, default: None ) –

    Producing physical part ID for read-only managed publications.

  • member (str | None, default: None ) –

    File or subtree within path. Requires path.

Returns:

  • dict[str, JsonValue] –

    The CLI list or members receipt. Missing or cleaned paths raise the native error;

  • dict[str, JsonValue] –

    live local outputs are outside the managed run namespace.

download_file(path: str, output: str | Path, *, scope: Literal['user', 'org'] | None = None, run_id: str | None = None, member: str = '') -> dict[str, JsonValue] async

Download a selected file or folder to an absent local destination.

Parameters:

  • path (str) –

    Target-relative library or managed publication path.

  • output (str | Path) –

    New local destination, relative to the captured client workspace.

  • scope (Literal['user', 'org'] | None, default: None ) –

    Library scope, defaulting to user. Cannot be combined with run_id.

  • run_id (str | None, default: None ) –

    The publication receipt's address.scope.runId, including after continuation.

  • member (str, default: '' ) –

    File or subtree within the selected tree; empty selects the whole tree.

Returns:

  • dict[str, JsonValue] –

    The CLI output-path receipt, after native framing and digest validation. File bytes

  • dict[str, JsonValue] –

    stream through the CLI's bounded transfer, never through Python JSON or run status.

remove_file(path: str, *, scope: Literal['user', 'org'] = 'user') -> dict[str, JsonValue] async

Remove one reusable library name and return the CLI removed receipt.

Parameters:

  • path (str) –

    Complete target-relative library name. Run publications are read-only.

  • scope (Literal['user', 'org'], default: 'user' ) –

    User or organization library. Accepted input pins remain independently owned.

Returns:

  • dict[str, JsonValue] –

    The CLI removed receipt, including whether a name was removed.

cleanup(*, all: bool = False) -> dict[str, JsonValue] async

Explicitly reclaim eligible retained data on the selected supporting target.

Parameters:

  • all (bool, default: False ) –

    Remove the 60-day age filter. Pending work remains protected. Libraries, live local outputs, logs and ledgers are outside cleanup's scope.

Returns:

  • dict[str, JsonValue] –

    The CLI cleaned receipt with publications and checkpointLineages removed.

list_presets() -> tuple[str, ...] async

Return built-in preset names read dynamically from the bundled executable.

list_targets() -> tuple[NamedTarget, ...] async

List local registrations, including platform, without contacting any target.

This reads the user's registry independently of this client's run target.

remove_target(name: str) -> TargetRemoveResult async

Remove a local registration, its stored login and resume permissions.

Parameters:

  • name (str) –

    Exact local target name.

Returns:

Raises:

get_preset(name: str, *, delivery: str | None = None) -> GraphSpec async

Read one built-in preset from the bundled executable.

Parameters:

  • name (str) –

    Exact native preset name.

  • delivery (str | None, default: None ) –

    Native delivery selector. None uses the executable-owned template default.

Returns:

  • GraphSpec –

    The GraphSpec emitted by Zeroshot, copied without changes.

Raises:

inbox(after: str | None = None, limit: int = 50) -> InboxPage async

Read open requests in running and suspended runs.

Parameters:

  • after (str | None, default: None ) –

    Opaque cursor returned by the previous page, or None for the first page.

  • limit (int, default: 50 ) –

    Maximum entries, from 1 through 100.

Returns:

  • InboxPage –

    The request page and its next cursor.

Raises:

  • ValueError –

    If limit is outside 1 through 100.

Run(client: Client, run_id: str, *, part_id: str | None = None)

Durable public run handle bound to one Client target.

part_id: str | None property

Return the selected historical part, or None when following the logical run.

current_part_id: str | None property

Return the most recently observed head, or None before the first lookup.

id: str property

Return the opaque public Zeroshot run identity.

status() -> RunStatus async

Read the current durable run status.

Returns:

  • RunStatus –

    The latest target projection.

Raises:

watch(*, after: str | None = None, follow: bool = False) -> AsyncGenerator[RunStatus, None] async

Watch run status until an actionable suspension or terminal result.

Parameters:

  • after (str | None, default: None ) –

    Last consumed opaque status cursor. None replays retained history.

  • follow (bool, default: False ) –

    Keep watching through suspensions and accepted continuations.

Returns:

  • AsyncGenerator[RunStatus, None] –

    An async iterator of immutable status snapshots.

Cancelling or closing the iterator detaches observation and does not stop the run.

logs(*, after: str | None = None, execution: str | None = None) -> AsyncIterator[LogEvent]

Open the durable redacted log stream with resume and execution filters.

Parameters:

  • after (str | None, default: None ) –

    Last consumed opaque log cursor. None replays retained logs.

  • execution (str | None, default: None ) –

    Opaque execution selector from RunStatus, or None for all records.

Returns:

  • AsyncIterator[LogEvent] –

    An async iterator of safe native log records.

Cancelling or closing the iterator detaches observation and does not stop the run.

wait(*, wait_timeout: float | None = None) -> RunResult async

Wait for the durable terminal result without controlling run lifetime.

Parameters:

  • wait_timeout (float | None, default: None ) –

    Non-negative observation deadline in seconds. None waits indefinitely.

Returns:

  • RunResult –

    The successful or failed terminal result.

Raises:

  • ValueError –

    If wait_timeout is negative.

  • RunWaitTimeout –

    If the deadline expires. The exception carries this run handle.

  • RunSuspendedError –

    If the attempt suspends; carries this handle and its status.

  • RunNotFoundError –

    If the target no longer retains this run.

  • TargetError –

    If observation fails.

  • ProtocolError –

    If native output is malformed.

Python task cancellation remains asyncio.CancelledError and leaves the run active.

suspend() -> RunStatus async

Request suspension and return the status immediately.

Returns:

  • RunStatus –

    The current durable status with the suspension request recorded.

resume(*, runtime: _Runtime | None = None, part_id: str | None = None, from_checkpoint: str | None = None, restart: bool = False, discard_workspace_changes: bool = False, operation_key: str | None = None) -> Run async

Continue a suspension or recover a failed run, optionally replacing its runtime.

Parameters:

  • part_id (str | None, default: None ) –

    Resume only if this explicitly selected part is still current.

  • from_checkpoint (str | None, default: None ) –

    Continue from this run-scoped checkpoint's graph boundary. Removed selections fail.

  • restart (bool, default: False ) –

    Restart at the original graph entry.

  • discard_workspace_changes (bool, default: False ) –

    Restore checkpoint files, or original prepared files at the root. By default the current workspace is kept.

  • operation_key (str | None, default: None ) –

    Required on hosted v2. Generate and retain it before calling resume. Reuse with identical arguments after a lost reply; omission refuses before writing. A new key intentionally starts a new recovery operation.

  • runtime (_Runtime | None, default: None ) –

    Complete replacement runtime. None retains the saved configuration. Native conversations use the harness's restoration and fresh-session fallback.

Returns:

  • Run –

    A handle with the same logical ID and the newly admitted current part.

request(*, request_id: str | None = None) -> InboxRequest async

Read a question, including its current state and successor part.

Parameters:

  • request_id (str | None, default: None ) –

    Select a question when multiple branches are waiting.

Returns:

answer(answer: JsonValue, *, part_id: str | None = None, request_id: str | None = None) -> Run async

Answer a request and continue its branch.

Parameters:

  • part_id (str | None, default: None ) –

    Require this part to be current. An addressed answer on a logical run follows the request across parts. A serial answer guards the observed part.

  • request_id (str | None, default: None ) –

    Required on hosted v2; select the exact request across handoffs. Local/direct targets and hosted v1 also accept a guarded serial answer without it.

  • answer (JsonValue) –

    Complete verifier result with signals and output matching the request.

Returns:

  • Run –

    A handle with the same logical ID and the part processing the answer.

  • Run –

    Invalid, repeated and late answers raise the CLI error.

steer(text: str, *, mode: Literal['once', 'standing'] = 'standing') -> RunSteer async

Record direction without continuing a suspended run.

Parameters:

  • text (str) –

    Nonblank UTF-8 direction, at most 262,144 bytes. Do not include secrets.

  • mode (Literal['once', 'standing'], default: 'standing' ) –

    Standing once per provider conversation, or once per node instance.

Returns:

  • RunSteer –

    The recorded steer, including its vector identity and receipt summary.

Raises:

  • ValueError –

    If mode is neither once nor standing.

  • RunNotFoundError –

    If the run is no longer retained.

  • TargetError –

    If the run refuses steering or transport fails.

  • ProtocolError –

    If native output is malformed.

checkpoints(*, after: str | None = None, limit: int = 50) -> CheckpointsPage async

Read an ordered checkpoint page using the deployed recovery capability.

Parameters:

  • after (str | None, default: None ) –

    Exclusive checkpoint ID. Removed selections fail without substitution.

  • limit (int, default: 50 ) –

    Page size, from 1 through 100.

Returns:

  • CheckpointsPage –

    A run-scoped inventory on hosted v2, or the legacy inventory on v1/local/direct.

export_workspace(output: str | Path, *, from_checkpoint: str | None = None) -> Path async

Download a raw workspace tar through the independent hosted export capability.

Parameters:

  • output (str | Path) –

    Explicit absent destination. The native client stages it privately.

  • from_checkpoint (str | None, default: None ) –

    Exact checkpoint ID, or None for the latest workspace.

Returns:

  • Path –

    The downloaded path. No extraction or recovery operation is performed.

vectors(*, after: str | None = None, limit: int = 50) -> RunVectorsPage async

Read one ordered page of the vector record.

Parameters:

  • after (str | None, default: None ) –

    Opaque entry cursor, or None for the first page.

  • limit (int, default: 50 ) –

    Number of entries, from 1 through 100.

Returns:

Raises:

  • ValueError –

    If limit is outside 1 through 100.

vector(id: str) -> RunVector async

Read a vector entry with its complete content.

Parameters:

  • id (str) –

    Opaque entry identity.

Returns:

force_stop() -> RunResult async

Force-stop this run and wait for its durable terminal result.

Returns:

  • RunResult –

    The terminal result. A stop before graph completion normally reports force_stopped.

  • RunResult –

    Stopping during the postmortem preserves the recorded graph result.

Raises:

discard_workspace() -> bool async

Delete this run's retained workspace or local recovery-lineage checkpoints.

Local runs keep their checkout, ledger, logs and delivery recovery state. Running or resuming lineage members refuse deletion; an uncontinued suspension must be force-stopped first, and an interrupted restore must be completed. Restarting a local failed run through resume() still uses the current checkout.

Returns:

  • bool –

    Whether retained workspace or checkpoint data was deleted.

Raises:

Stack(client: Client, stack_id: str)

Durable hosted stack handle bound to one Client target.

A "stacked_pull_requests" stack is complete once every pull request is open; Zeroshot never merges, retargets, or restacks them. Merge them from the bottom up: GitHub moves a child pull request onto the base branch when its merged parent's branch is deleted. A squash-merged parent leaves the child to rebase onto the base branch, and changes pushed to a parent pull request during review are not restacked, so rebase the pull requests above it by hand.

id: str property

Return the opaque server-assigned stack identity.

status() -> StackStatus async

Read the stack's current aggregate status.

watch() -> AsyncIterator[StackStatus]

Poll and yield changed aggregate snapshots until the stack is terminal.

Cancelling or closing the iterator detaches observation and leaves runs active.

wait(*, wait_timeout: float | None = None) -> StackStatus async

Wait for a terminal aggregate status without controlling stack lifetime.

Parameters:

  • wait_timeout (float | None, default: None ) –

    Non-negative observation deadline in seconds. None waits indefinitely.

Raises:

  • ValueError –

    If wait_timeout is negative.

  • StackWaitTimeout –

    If observation expires; it carries this durable handle.

  • TargetError –

    If the selected target is unavailable.

  • ProtocolError –

    If native output is malformed.

force_stop() -> StackStatus async

Force every nonterminal run to stop and wait for aggregate termination.

await run.steer(text) returns a RunSteer receipt for standing direction. It follows the handle's local or named-target route, leaves suspended runs suspended and uses the existing typed errors. Pass mode="once" to deliver once per node instance; mode="standing" remains the default. Read complete text through Run.vector(receipt.id).