RunAgent Rust SDK
Rust bindings for the RunAgent platform. Use it to call agents you deploy with the CLI—whether they run locally on your laptop or remotely on backend.run-agent.ai.
Installation
[]
= "0.1"
= { = "1.35", = ["full"] }
= "1.0"
= "0.3"
Configuration Overview
The SDK uses a single constructor pattern. All configuration is done through RunAgentClientConfig:
use RunAgentClientConfig;
// Local agent with explicit address
let client = new.await?;
// Remote agent
let client = new.await?;
// Remote agent with persistent memory
let client = new.await?;
| Setting | Cloud | Local (auto discovery) | Local (explicit) |
|---|---|---|---|
local |
false (default) |
true |
true |
| Host / Port | derived from URL | looked up via SQLite | with_address() |
| Base URL | RUNAGENT_BASE_URL || default |
n/a | n/a |
| API Key | RUNAGENT_API_KEY (required) |
optional | optional |
| Registry | n/a | true (default) |
false |
user_id |
optional | optional | optional |
persistent_memory |
optional (false default) |
optional (false default) |
optional (false default) |
RUNAGENT_API_KEY: Bearer token for remote agents (can be set via env var orwith_api_key()).RUNAGENT_BASE_URL: Override the default cloud endpoint (e.g. staging).user_id: Optional user identifier for persistent storage across agent executions.persistent_memory: Enable persistent memory to maintain state across multiple agent calls (default:false).- For local discovery, install the crate with the
dbfeature and ensure the CLI has registered the agent in~/.runagent/runagent_local.db.
Usage
Sync (Blocking) - Simplest
Non-streaming
use ;
use json;
Streaming
use ;
use json;
Async (Recommended)
Non-streaming
use ;
use json;
async
Streaming
use ;
use json;
use StreamExt;
async
Alternative: Builder Pattern
You can also use the builder pattern instead of direct struct construction:
use ;
// Async
let client = new.await?;
// Sync
use RunAgentClient;
let client = new?;
Local Agents
With explicit address
use ;
let client = new.await?;
With auto-discovery (requires db feature)
let client = new.await?;
Guardrails: tags ending with
_streamcan only be run viarun_stream*. Non-stream tags must be run viarun*. The client raises clear errors (STREAM_ENTRYPOINT,NON_STREAM_ENTRYPOINT) with suggestions.
Architecture Expectations
During initialization the client calls /api/v1/agents/{id}/architecture and expects the envelope:
- If
success === falsewe propagateerror.code/message/suggestion/details. - If
data.entrypointsis missing we raiseARCHITECTURE_MISSING. - When an entrypoint can’t be found we log the list returned by the server to help debug typos.
API Reference
Client Creation
| Method | Description |
|---|---|
RunAgentClient::new(config: RunAgentClientConfig) |
Single constructor for all client types. |
Configuration Builder
| Method | Description |
|---|---|
RunAgentClientConfig::new(agent_id, entrypoint_tag) |
Create config with required fields. |
.with_local(bool) |
Set local flag (default: false). |
.with_address(host, port) |
Set explicit host/port for local agents. |
.with_api_key(key) |
Set API key (overrides env var). |
.with_base_url(url) |
Override default base URL. |
.with_enable_registry(bool) |
Enable/disable database lookup (default: true for local). |
.with_user_id(user_id) |
Set user ID for persistent storage. |
.with_persistent_memory(bool) |
Enable persistent memory across executions (default: false). |
.with_extra_params(params) |
Set extra parameters for future use. |
Client Methods
| Method | Description |
|---|---|
run / run_with_args |
Execute non-streaming entrypoints. |
run_stream / run_stream_with_args |
Execute streaming entrypoints (async stream of Value). |
health_check |
Check if the agent is reachable. |
get_agent_architecture |
Fetch the normalized architecture (see above). |
All methods return RunAgentResult<T> where RunAgentError::Execution { code, message, suggestion, details } carries actionable metadata (e.g. AGENT_NOT_FOUND_REMOTE, STREAM_ENTRYPOINT, AUTHENTICATION_ERROR). Inspect these fields to guide users.
Troubleshooting
| Symptom | Resolution |
|---|---|
STREAM_ENTRYPOINT |
Call run_stream* or switch to a non-stream tag. |
NON_STREAM_ENTRYPOINT |
Call run* or deploy a _stream entrypoint. |
AGENT_NOT_FOUND_LOCAL |
Ensure the agent is registered locally (runagent serve or runagent config --register-agent). |
AGENT_NOT_FOUND_REMOTE |
Verify the agent ID and that your API key has access. |
AUTHENTICATION_ERROR |
Set RUNAGENT_API_KEY env var or use .with_api_key() in config. |
ARCHITECTURE_MISSING |
Redeploy the agent; ensure entrypoints are defined in runagent.config.json. |
Security Best Practices
- Never hardcode API keys; use env vars or secret managers.
- For browser/edge bridging, proxy calls through your backend rather than exposing long-lived keys.
- When running locally, restrict access to
~/.runagent/runagent_local.db.
Development & Publishing
To publish a new release, follow ../PUBLISH.md (version bump, cargo package, cargo publish, tag release).
Need Help?
- Docs:
docs/sdk/rust/(coming soon) or https://docs.rs/runagent - Issues: github.com/runagent-dev/runagent/issues
- Community: Discord link in the main repo README
- Commercial support: contact the RunAgent team via the dashboard