Skip to main content
Use RunAgent agents from Rust applications with high-performance, type-safe execution.

Prerequisites

Overview

The Rust SDK provides production-ready access to RunAgent agents with:
  • Zero-cost abstractions for optimal performance
  • Futures-based async operations powered by Tokio
  • Compile-time type safety with comprehensive error handling
  • Seamless integration with Rust’s ownership model

Installation

Add the following dependencies to your Cargo.toml:

Basic Usage

Synchronous Execution

Execute an agent and wait for the complete response:

Asynchronous Execution

Process multiple requests concurrently for improved throughput:

Advanced Features

Streaming Responses

Process responses as they arrive for real-time applications:

Error Handling

Handle different error types with Rust’s type-safe error handling:

Custom Configuration

Configure the client with custom headers and timeouts:

Configuration

Environment Variables

Configure the SDK using environment variables:

Configuration File

Create ~/.runagent/config.json:

Programmatic Configuration

Configure the client directly in code:

Best Practices

Connection Management

Implement a connection manager for efficient resource usage:

Retry Logic

Implement exponential backoff for resilient operations:

Logging and Monitoring

Add observability to your agent interactions:

Common Patterns

Agent Factory Pattern

Create agents with consistent configuration:

Agent Wrapper Pattern

Encapsulate agent functionality with a clean interface:

Agent Pool Pattern

Distribute load across multiple agent instances:

Performance Optimization

Connection Pooling

Reuse connections for improved performance:

Response Caching

Cache responses for frequently requested data:

Testing

Unit Testing

Test your agent interactions:

Integration Testing

Test complete workflows:

Next Steps

Continue your journey with RunAgent:

Summary

You have learned how to use RunAgent agents from Rust applications. The Rust SDK provides high-performance access with zero-cost abstractions and compile-time type safety, making it ideal for production deployments requiring maximum performance and reliability.