AgentTrust ID Rust SDK
Rust SDK for AgentTrust ID -- authentication and authorization for AI agents.
Installation
Add to your Cargo.toml:
[]
= "0.3"
Quick Start
use ;
Guard Pattern
For agents using raw OpenAI/Anthropic SDKs, the AgentTrustGuard provides a simple check-then-report pattern with automatic telemetry buffering and flush-on-drop:
use ;
Environment Variables
| Variable | Description | Default |
|---|---|---|
AGENTTRUST_URL |
Gateway base URL | http://localhost:8080 |
AGENTTRUST_BASE_URL |
Fallback for AGENTTRUST_URL |
http://localhost:8080 |
AGENTTRUST_API_KEY |
Organization API key | (none) |
let client = from_env?;
Error Handling
All fallible operations return Result<T, AgentTrustError>. Use pattern matching for specific error handling:
use ;
let client = builder.build.unwrap;
match client.agents.get
AgentTrustError Variants
| Variant | Description |
|---|---|
Authentication { message, status } |
HTTP 401 -- invalid or missing API key |
Authorization { message, status } |
HTTP 403 -- insufficient permissions |
Validation { message, status } |
HTTP 400 -- request validation failed |
NotFound { message, status } |
HTTP 404 -- resource does not exist |
Network(reqwest::Error) |
Connection refused, timeout, DNS failure |
ActionDenied { message, check_id } |
Guard check returned "denied" (check_id is Option<String>) |
GuardianUnavailable { message } |
Guardian service unreachable and fail_open is false |
Api { message, code, status } |
Generic API error for other HTTP status codes |
Json(serde_json::Error) |
JSON serialization or deserialization failed |
The ActionDenied and GuardianUnavailable variants are especially relevant when using AgentTrustGuard.
Features
| Feature | Description | Default |
|---|---|---|
blocking |
Synchronous (blocking) HTTP client | Yes |
async |
Async support via tokio |
No |
The SDK uses blocking HTTP by default, which is simpler for most agent use cases. Enable the async feature for non-blocking I/O:
[]
= { = "0.3", = false, = ["async"] }
API Reference
AgentTrustClient
AgentTrustClient::builder()-- Configure with builder patternAgentTrustClient::from_env()-- Configure from environment variablesclient.health()-- Health checkclient.agents()-- Agent managementclient.tokens()-- Token operationsclient.actions()-- Action authorizationclient.telemetry()-- Telemetry reportingclient.sessions()-- AgentTrust session managementclient.approvals()-- Elevation approval workflowclient.agentcards()-- A2A agent card publishingclient.a2a()-- Agent-to-agent task dispatchclient.mcp()-- MCP server registry and proxyclient.delegations()-- Capability delegation chainsclient.federation()-- Cross-org OIDC federationclient.streaming()-- SIEM streaming destinationsclient.wimse()-- WIMSE workload identity tokens
AgentsAPI
create(req)-- Register a new agent (returns private key)get(id)-- Get agent by IDlist(org_id: Option<&str>)-- List agents; passNoneto list all agentsrevoke(id, reason)-- Permanently revoke an agent
TokensAPI
issue(req)-- Issue an opaque agent tokenintrospect(req)-- Introspect a token server-siderevoke(token, reason)-- Revoke a token
ActionsAPI
check(req)-- Pre-flight action authorization check
TelemetryAPI
report(agent_id, session_id, events)-- Report telemetry events
SessionsAPI
init_session(agent_id, server_id)-- Initialize an MCP sessionget_session(session_id)-- Retrieve a session
ApprovalsAPI
approve(approval_id, decided_by)-- Approve an elevationdeny(approval_id, decided_by)-- Deny an elevationget(approval_id)-- Get approval status
AgentCards
generate(agent_id)-- Generate a cardget(agent_id)-- Fetch the current cardpublish(agent_id)-- Publish (make publicly discoverable)get_public(agent_id)-- Fetch a public agent card
A2A
send_message(agent_id, text, message_id, task_id)-- Send an A2A v1.0message/sendto an agentcreate_task(req)-- Send a task to a target agent (tasks/send)get_task(id)-- Get task statuscancel_task(id)-- Cancel a running tasklist_tasks()-- List recent tasks
Mcp
list_servers()-- List registered MCP serversget_server(id)-- Get MCP server by IDregister_server(req)-- Register a new MCP serverremove_server(id)-- Remove an MCP servercall_tool(server_id, agent_id, method, params, session_id)-- JSON-RPC proxy call
Delegations
create(req)-- Create a delegationget(id)-- Get delegation by IDlist()-- List delegationsrevoke(id)-- Revoke a delegationinit_session(id)-- Bridge a delegation into a session
Federation
register_provider(req)-- Register an OIDC providerlist_providers()-- List providersdelete_provider(id)-- Remove a providerissue_token(agent_id, req)-- Issue a federated ID tokenintrospect_token(req)-- Verify a federated tokenrevoke_token(token)-- Revoke a federated tokeninit_session(req)-- Bridge a federated token into a session
Streaming
create(req)-- Create a SIEM destinationlist()-- List SIEM destinationsget(id)-- Get a SIEM destinationupdate(id, req)-- Update a SIEM destinationdelete(id)-- Delete a SIEM destinationdelivery_log(id)-- Recent delivery recordstest(id)-- Send a test eventsubscribe(filter, handler)-- Polling subscription stub for delivery log
Wimse
issue_token(req)-- Issue a WIMSE workload identity tokenverify_wimse(req)-- Verify a WIMSE tokenget_jwt_signed_headers(req)-- Build the headers to attach downstream
AgentTrustGuard
AgentTrustGuard::new(client, agent_id)-- Create with defaultsAgentTrustGuard::builder(client, agent_id)-- Configure with builderguard.check(tool, input)-- Pre-flight checkguard.report(tool, success, ms)-- Record tool resultguard.flush()-- Send buffered events- Auto-flushes at 10 events and on
Drop
License
Apache License 2.0 - see LICENSE in this directory.