Skip to content

openagents_sdk::labs::worker

Signing a computer up to run Lab jobs for an account, and a client that can only run jobs. Requests send once. Retain attempts and finish requests after response loss; observing a started assignment does not grant permission to spawn it again.

ItemWhat it does
Client structA client whose credential authorizes only its worker's assigned work.
CredentialRecord structA worker's saved key and the deployment it belongs to.
MAX_INPUT_FILE constThe largest input file the service returns in one read.

Client

pub struct Client {}

A client whose credential authorizes only its worker's assigned work. It cannot authenticate as an account, read documents, or choose an executable.

Client::labs_worker

pub fn labs_worker(&self, token: &str) -> Result<Client, Error>

Import a job-only key explicitly. The next worker request checks it with the service; this does not create an account session.

Client::restore_labs_worker

pub fn restore_labs_worker(&self, record: &CredentialRecord) -> Result<Client, Error>

Restores a worker client from a saved credential for this deployment.

Client::worker_ref

pub fn worker_ref(&self, space: &str, id: &str) -> Result<WorkerRef, Error>

Checks a space and ID and returns a worker reference.

Client::enroll_worker

pub async fn enroll_worker(
    &self,
    request: &Request<Enroll>,
    cancel: &CancellationToken,
) -> Result<Enrolled, Error>

Enrolls a worker for the account and returns its job-only key.

Calls POST /v1/labs/workers

Client::revoke_worker

pub async fn revoke_worker(
    &self,
    worker: &WorkerRef,
    cancel: &CancellationToken,
) -> Result<bool, Error>

Revokes a worker's key and returns whether it was revoked.

Client::job_usage

pub async fn job_usage(
    &self,
    job: &JobRef,
    cancel: &CancellationToken,
) -> Result<Vec<Usage>, Error>

Returns the usage that workers recorded for a job.

Client::record

pub fn record(&self) -> CredentialRecord

Returns the credential to save so you can restore this client later.

Client::worker_id

pub fn worker_id(&self) -> &str

Returns this worker's ID.

Client::clear_credential

pub fn clear_credential(&self)

Stop this client's clones locally. Use retire to revoke the remote key, and remove any caller-owned saved credential separately.

Client::with_timeout

pub fn with_timeout(mut self, timeout: Duration) -> Result<Self, Error>

Sets the request timeout, up to two minutes.

Client::inputs

pub async fn inputs(
    &self,
    work: &Work,
    cancel: &CancellationToken,
) -> Result<Inputs, Error>

What started work may read: its version, the versions it references in its space, and their stored source files. The service checks the key, the space, and the lease again on every call.

Calls POST /v1/inputs

Client::input_file

pub async fn input_file(
    &self,
    work: &Work,
    file: &lab_kit::Artifact,
    cancel: &CancellationToken,
) -> Result<Vec<u8>, Error>

Read one file inputs listed, checked against its size and checksum.

Calls POST /v1/inputs/file

Client::poll

pub async fn poll(
    &self,
    request: &Poll,
    cancel: &CancellationToken,
) -> Result<Available, Error>

Asks for work, waiting up to 25 seconds for an assignment.

Calls POST /v1/poll

Client::start

pub async fn start(
    &self,
    request: &Attempt,
    cancel: &CancellationToken,
) -> Result<Work, Error>

Marks an assigned attempt as started and returns its work.

Client::heartbeat

pub async fn heartbeat(
    &self,
    request: &Attempt,
    cancel: &CancellationToken,
) -> Result<Work, Error>

Tells the service the attempt is still running and returns its work.

Client::finish

pub async fn finish(
    &self,
    request: &Finish,
    cancel: &CancellationToken,
) -> Result<lab_kit::JobState, Error>

Send a retained finish request once. An identical retry after response loss is safe; a response never grants permission to execute the job again.

Calls POST /v1/finish

Client::retire

pub async fn retire(&self, cancel: &CancellationToken) -> Result<bool, Error>

Revokes this worker's key and stops the client if the revoke succeeds.

Calls DELETE /v1/*

CredentialRecord

pub struct CredentialRecord {}

A worker's saved key and the deployment it belongs to.

MAX_INPUT_FILE

pub const MAX_INPUT_FILE: usize = 64 * 1024 * 1024;

The largest input file the service returns in one read.

Re-exported from other crates

  • Assignment from lab_kit::worker
  • Capabilities from lab_kit::worker
  • EffectiveRequirements from lab_kit::worker
  • Enrolled from lab_kit::worker
  • Lease from lab_kit::worker
  • Placement from lab_kit::worker
  • Usage from lab_kit::worker
  • Worker from lab_kit::worker
  • protocol from lab_kit::worker