Documentation home

Rust SDK

Use the Rust SDK for safety-critical workers and high-throughput services.

Install

Install the recording and Semiotic Probe release directly from GitHub using this Cargo dependency:

haltstate = { git = "https://github.com/haltstate-ai/sdk-rust", tag = "v0.2.0-dev.1" }

Use this published Git tag as a Cargo dependency; no crates.io account is required.

Install this published release explicitly to use recording and Semiotic Probes. Existing integrations remain on the Standard contract unless enrolled for replay. Semiotic Probes use an isolated model hook, your existing tenant API key and the server-managed low-frequency schedule.

Guard shape

use haltstate::{Client, Config, GuardOutcome};
use serde_json::json;

let client = Client::new(Config {
    tenant_id: Some(std::env::var("HALTSTATE_TENANT_ID")?),
    api_key: Some(std::env::var("HALTSTATE_API_KEY")?),
    ..Default::default()
})?;
let operator_epoch = "11111111-2222-4333-8444-555555555555";
let destination_key = "refund:lge_123";
let guard_key = format!("hsr1:{operator_epoch}:{destination_key}");
let report_id = "40000000-0000-4000-8000-000000000501";
let permit = client
    .guard(
        "refund.create",
        json!({"amount": 126, "currency": "USD"}),
        Some(guard_key.as_str()),
        Some("retail-refund-agent"),
    )
    .await?;
permit.ensure_current()?;
match execute_refund_once(destination_key).await {
    Ok(result) => {
        client.report_guard_outcome(
            &permit, report_id, GuardOutcome::Success, Some(result), None,
        ).await?;
    }
    Err(action_error) => {
        let message = action_error.to_string();
        client.report_guard_outcome(
            &permit, report_id, GuardOutcome::Error, None, Some(message.as_str()),
        ).await?;
        return Err(action_error.into());
    }
}

Persist the permit, report ID, outcome, and exact payload before retrying report_guard_outcome. Never rerun the destination action merely to obtain a receipt.

Full operation identity

use haltstate::{Client, Config, GuardOutcome};
use serde_json::json;

let client = Client::new(Config {
    tenant_id: Some(std::env::var("HALTSTATE_TENANT_ID")?),
    api_key: Some(std::env::var("HALTSTATE_API_KEY")?),
    ..Default::default()
})?;
let operator_epoch = "11111111-2222-4333-8444-555555555555";
let destination_key = format!("refund:{}", ledger_entry_id);
let guard_key = format!("hsr1:{operator_epoch}:{destination_key}");
let report_id = "40000000-0000-4000-8000-000000000501";
let permit = client
    .guard_with_context(
        "refund.create",
        json!({"amount": 126, "currency": "USD"}),
        Some(guard_key.as_str()),
        Some("retail-refund-agent"),
        Some("refund/ledger-entry"),
        Some("low"),
    )
    .await?;
permit.ensure_current()?;
match execute_refund_once(destination_key.as_str()).await {
    Ok(result) => {
        client.report_guard_outcome(
            &permit, report_id, GuardOutcome::Success, Some(result), None,
        ).await?;
    }
    Err(action_error) => {
        let message = action_error.to_string();
        client.report_guard_outcome(
            &permit, report_id, GuardOutcome::Error, None, Some(message.as_str()),
        ).await?;
        return Err(action_error.into());
    }
}

Replay-enabled SDK contract

The stable retry identity binds the exact agent, action or tool, resource, normalized parameters, risk class, and immutable policy version. With an operator-issued activation epoch, the SDK may create epoch-qualified generated keys only when the caller omitted a key; explicit keys are never changed. Approval expiry blocks a stale permit, while already_started and completed remain terminal. After the side effect, receipt validation requires the durable event ID, receipt hash, received flag, and duplicate marker; retry the same report identity without rerunning the action.

Use this contract only for an explicitly enrolled replay integration. Published release channels and version-specific features are listed above; package installation alone does not activate replay routing.

Implementation notes

Keep the HaltState call as close as possible to the side effect. The agent may plan and draft freely, but the wrapper around the actual action should be the place where authority is checked. That wrapper should send only the context required for policy evaluation: safe identifiers, normalized amounts, action names, risk flags, schedule windows, and redaction status. Raw customer payloads and secrets should stay in the business system or protected operator tooling.

Operational evidence

For each action, preserve the decision, the worker outcome, the idempotency key, safe resource references, latency, proof status, and redaction status. This evidence supports incident response and control narratives because it shows what the system did at runtime rather than only describing what the policy document intended. HaltState supports alignment work; it is not a substitute for legal advice or a compliance certification.