pub struct ResourceLimits { /* private fields */ }Expand description
Resource limits configuration for fine-grained concurrency control.
This struct allows you to set different concurrency limits for different types of operations, preventing any single resource type from overwhelming external services or consuming too many system resources.
Resource limits are applied based on tool name prefixes:
- Tools starting with
solana_use the “solana_rpc” resource pool - Tools starting with
evm_use the “evm_rpc” resource pool - Tools starting with
web_use the “http_api” resource pool - All other tools use the default concurrency limit
§Examples
use riglr_core::ResourceLimits;
// Create limits for different resource types
let limits = ResourceLimits::default()
.with_limit("solana_rpc", 3) // Max 3 concurrent Solana RPC calls
.with_limit("evm_rpc", 8) // Max 8 concurrent EVM RPC calls
.with_limit("http_api", 15) // Max 15 concurrent HTTP requests
.with_limit("database", 5); // Max 5 concurrent database operations
// Use default limits (solana_rpc: 5, evm_rpc: 10, http_api: 20)
let default_limits = ResourceLimits::default();§Resource Pool Mapping
The system automatically maps tool names to resource pools:
Tool Name → Resource Pool → Limit
"solana_balance" → "solana_rpc" → configured limit
"evm_swap" → "evm_rpc" → configured limit
"web_fetch" → "http_api" → configured limit
"custom_tool" → default → ExecutionConfig.max_concurrencyImplementations§
Source§impl ResourceLimits
impl ResourceLimits
Sourcepub fn with_limit(self, resource: impl Into<String>, limit: usize) -> Self
pub fn with_limit(self, resource: impl Into<String>, limit: usize) -> Self
Add a resource limit for the specified resource type.
This creates a semaphore that will limit concurrent access to the specified resource. Tools with names matching the resource mapping will be subject to this limit.
§Parameters
resource- The resource identifier (e.g., “solana_rpc”, “evm_rpc”)limit- Maximum number of concurrent operations for this resource
§Returns
Self, for method chaining
§Examples
use riglr_core::ResourceLimits;
let limits = ResourceLimits::default()
.with_limit("solana_rpc", 3) // Limit Solana RPC calls
.with_limit("database", 10) // Limit database connections
.with_limit("external_api", 5); // Limit external API callsSourcepub fn get_semaphore(&self, resource: &str) -> Option<Arc<Semaphore>>
pub fn get_semaphore(&self, resource: &str) -> Option<Arc<Semaphore>>
Get the semaphore for a specific resource type.
This is used internally by the ToolWorker to acquire permits
before executing tools. Returns None if no limit is configured
for the specified resource.
§Parameters
resource- The resource identifier to look up
§Returns
Some(Arc<Semaphore>)- If a limit is configured for this resourceNone- If no limit is configured (will use default limit)
§Examples
use riglr_core::ResourceLimits;
let limits = ResourceLimits::default()
.with_limit("test_resource", 5);
assert!(limits.get_semaphore("test_resource").is_some());
assert!(limits.get_semaphore("unknown_resource").is_none());Trait Implementations§
Source§impl Clone for ResourceLimits
impl Clone for ResourceLimits
Source§fn clone(&self) -> ResourceLimits
fn clone(&self) -> ResourceLimits
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more