ResourceLimits

Struct ResourceLimits 

Source
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_concurrency

Implementations§

Source§

impl ResourceLimits

Source

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 calls
Source

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 resource
  • None - 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

Source§

fn clone(&self) -> ResourceLimits

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResourceLimits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResourceLimits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,