Skip to content

openagents_sdk::agents

Private, revisioned agent definitions. Saving a definition never starts work.

ItemWhat it does
AgentPage structOne page of agent definitions and the cursor for the next page.
AgentRequest structA saved mutation belongs to exactly one account and deployment.
Agents structCalls the agent definition and assignment routes for one signed-in session.
CreateAgent structThe request body that saves a new agent definition.
DeleteAgent structThe request body that deletes an agent definition at an expected revision.
UpdateAgent structThe request body that replaces an agent definition at an expected revision.
request_id fnReturns a new random request ID as 64 hexadecimal characters.

AgentPage

pub struct AgentPage {
    pub data: Vec<AgentDefinition>,
    pub next: Option<String>,
}

One page of agent definitions and the cursor for the next page.

AgentRequest

pub struct AgentRequest<T> {
    pub body: T,
}

A saved mutation belongs to exactly one account and deployment. Keep it across retries.

Agents

pub struct Agents<'a> {}

Calls the agent definition and assignment routes for one signed-in session.

Agents::assignment_request

pub fn assignment_request(
    &self,
    spec: AssignmentSpec,
) -> Result<AgentRequest<CreateAssignment>, Error>

Checks spec and prepares a request that creates an assignment.

Agents::command_request

pub fn command_request(
    &self,
    action: AssignmentAction,
) -> Result<AgentRequest<AssignmentCommand>, Error>

Checks action and prepares a request that sends it to an assignment.

Agents::report_request

pub fn report_request(
    &self,
    host: String,
    expected_revision: u64,
    state: AssignmentState,
    result: Option<String>,
    active_command: Option<String>,
    after_seq: u64,
) -> Result<AgentRequest<AssignmentReport>, Error>

Prepares a request a computer uses to report an assignment's state.

Agents::assign

pub async fn assign(
    &self,
    request: &AgentRequest<CreateAssignment>,
    cancel: &CancellationToken,
) -> Result<Assignment, Error>

Creates an assignment from a prepared request.

Calls POST /v1/agent-assignments

Agents::assignment

pub async fn assignment(
    &self,
    id: &str,
    cancel: &CancellationToken,
) -> Result<Assignment, Error>

Fetches the assignment id.

Calls GET /v1/agent-assignments/{id}

Agents::assignments

pub async fn assignments(
    &self,
    host: Option<&str>,
    after: Option<&str>,
    cancel: &CancellationToken,
) -> Result<AssignmentPage, Error>

Lists assignments, optionally for one computer, starting after the cursor after.

Calls GET /v1/agent-assignments

Agents::command

pub async fn command(
    &self,
    id: &str,
    request: &AgentRequest<AssignmentCommand>,
    cancel: &CancellationToken,
) -> Result<Assignment, Error>

Sends a prepared user action to the assignment id.

Calls POST /v1/agent-assignments/{id}/commands

Agents::report

pub async fn report(
    &self,
    id: &str,
    request: &AgentRequest<AssignmentReport>,
    cancel: &CancellationToken,
) -> Result<Assignment, Error>

Sends a prepared state report for the assignment id.

Calls POST /v1/agent-assignments/{id}/report

Agents::create_request

pub fn create_request(
    &self,
    spec: AgentSpec,
) -> Result<AgentRequest<CreateAgent>, Error>

Checks spec and prepares a request that saves it as a new agent.

Agents::update_request

pub fn update_request(
    &self,
    expected_revision: u64,
    spec: AgentSpec,
) -> Result<AgentRequest<UpdateAgent>, Error>

Checks spec and prepares a request that replaces the agent at expected_revision.

Agents::delete_request

pub fn delete_request(
    &self,
    expected_revision: u64,
) -> Result<AgentRequest<DeleteAgent>, Error>

Prepares a request that deletes the agent at expected_revision.

Agents::list

pub async fn list(
    &self,
    after: Option<&str>,
    limit: usize,
    cancel: &CancellationToken,
) -> Result<AgentPage, Error>

Lists up to limit agent definitions (1 to 100), starting after the cursor after.

Calls GET /v1/agent-definitions

Agents::get

pub async fn get(
    &self,
    id: &str,
    revision: Option<u64>,
    cancel: &CancellationToken,
) -> Result<AgentDefinition, Error>

Fetches one agent definition, at revision when given or the latest otherwise.

Calls GET /v1/agent-definitions/{id}

Agents::create

pub async fn create(
    &self,
    request: &AgentRequest<CreateAgent>,
    cancel: &CancellationToken,
) -> Result<AgentDefinition, Error>

Saves a new agent definition from a prepared request.

Calls POST /v1/agent-definitions

Agents::update

pub async fn update(
    &self,
    id: &str,
    request: &AgentRequest<UpdateAgent>,
    cancel: &CancellationToken,
) -> Result<AgentDefinition, Error>

Replaces the agent definition id from a prepared request.

Calls PUT /v1/agent-definitions/{id}

Agents::delete

pub async fn delete(
    &self,
    id: &str,
    request: &AgentRequest<DeleteAgent>,
    cancel: &CancellationToken,
) -> Result<AgentDefinition, Error>

Deletes the agent definition id from a prepared request.

Calls DELETE /v1/agent-definitions/{id}

CreateAgent

pub struct CreateAgent {
    pub request_id: String,
    pub spec: AgentSpec,
}

The request body that saves a new agent definition.

DeleteAgent

pub struct DeleteAgent {
    pub request_id: String,
    pub expected_revision: u64,
}

The request body that deletes an agent definition at an expected revision.

UpdateAgent

pub struct UpdateAgent {
    pub request_id: String,
    pub expected_revision: u64,
    pub spec: AgentSpec,
}

The request body that replaces an agent definition at an expected revision.

request_id

pub fn request_id() -> Result<String, Error>

Returns a new random request ID as 64 hexadecimal characters.

Re-exported from other crates

  • ANY_RUNTIME from agent_contract
  • Access from agent_contract
  • AgentDefinition from agent_contract
  • AgentSpec from agent_contract
  • MAX_FALLBACKS from agent_contract
  • Profile from agent_contract
  • RuntimeChoice from agent_contract
  • valid_id from agent_contract