Skip to main content

ToolConcurrencyManager

Struct ToolConcurrencyManager 

Source
pub struct ToolConcurrencyManager { /* private fields */ }
Expand description

Core traits and types.

Always available regardless of feature flags. Includes:

  • Agent - The fundamental trait for all agents
  • Tool / Toolset - For extending agents with capabilities
  • Session / State - For managing conversation context
  • Event - For streaming agent responses
  • AdkError / Result - Unified error handling Manages semaphores for tool concurrency enforcement.

Created from a ToolConcurrencyConfig, the manager pre-allocates semaphores for the global limit and each per-tool override. Use acquire to obtain a ConcurrencyPermit before executing a tool.

§Example

use adk_core::{
    BackpressurePolicy, ToolConcurrencyConfig, ToolConcurrencyManager,
};
use std::collections::HashMap;

let config = ToolConcurrencyConfig {
    max_concurrency: Some(5),
    per_tool: HashMap::from([("expensive_tool".to_string(), 1)]),
    backpressure: BackpressurePolicy::Queue,
};

let manager = ToolConcurrencyManager::new(&config);

// Only 1 "expensive_tool" can run at a time
let permit = manager.acquire("expensive_tool").await.unwrap();
// ... run tool ...
drop(permit);

// Other tools use the global limit of 5
let permit = manager.acquire("cheap_tool").await.unwrap();
drop(permit);

Implementations§

Source§

impl ToolConcurrencyManager

Source

pub fn new(config: &ToolConcurrencyConfig) -> ToolConcurrencyManager

Available on crate feature runner only.

Create a new manager from the given configuration.

Allocates semaphores based on the config:

  • A global semaphore with max_concurrency permits (if set)
  • Per-tool semaphores for each entry in per_tool
§Example
use adk_core::{ToolConcurrencyConfig, ToolConcurrencyManager};

let config = ToolConcurrencyConfig {
    max_concurrency: Some(10),
    ..Default::default()
};
let manager = ToolConcurrencyManager::new(&config);
Source

pub fn has_limits(&self) -> bool

Available on crate feature runner only.

Returns true if this manager has any concurrency limits configured.

When no limits are configured (no global limit and no per-tool overrides), calling acquire always succeeds immediately with no semaphore enforcement.

Source

pub async fn acquire( &self, tool_name: &str, ) -> Result<ConcurrencyPermit, AdkError>

Available on crate feature runner only.

Acquire a permit for the named tool.

If a per-tool override exists for tool_name, the per-tool semaphore is used. Otherwise, the global semaphore is used (if configured). When neither a per-tool override nor a global limit is configured, a permit is returned immediately with no semaphore enforcement.

§Errors

Returns AdkError when BackpressurePolicy::Fail is configured and no permit is immediately available.

§Example
use adk_core::{
    BackpressurePolicy, ToolConcurrencyConfig, ToolConcurrencyManager,
};

let config = ToolConcurrencyConfig {
    max_concurrency: Some(1),
    backpressure: BackpressurePolicy::Fail,
    ..Default::default()
};
let manager = ToolConcurrencyManager::new(&config);

// First acquire succeeds
let permit1 = manager.acquire("tool_a").await.unwrap();

// Second acquire fails immediately (Fail policy)
let result = manager.acquire("tool_b").await;
assert!(result.is_err());

drop(permit1);

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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