Skip to main content

EnhancedPluginManager

Struct EnhancedPluginManager 

Source
pub struct EnhancedPluginManager { /* private fields */ }
Available on crate feature plugin only.
Expand description

Manages enhanced plugins with priority-based pipeline execution.

Plugins are stored sorted by priority (ascending). All pipeline methods iterate plugins in this order, passing each plugin’s output as input to the next plugin in the chain.

§Thread Safety

EnhancedPluginManager is Send + Sync and can be shared across async tasks via Arc<EnhancedPluginManager>.

Implementations§

Source§

impl EnhancedPluginManager

Source

pub fn new(plugins: Vec<Arc<dyn EnhancedPlugin>>) -> EnhancedPluginManager

Creates a new EnhancedPluginManager with the given plugins.

Plugins are sorted by priority in ascending order using a stable sort, so plugins with the same priority retain their registration order.

§Examples
use std::sync::Arc;
use adk_plugin::{EnhancedPluginManager, EnhancedPlugin};

let plugins: Vec<Arc<dyn EnhancedPlugin>> = vec![
    Arc::new(MyPlugin),
];
let manager = EnhancedPluginManager::new(plugins);
Source

pub fn with_config( plugins: Vec<Arc<dyn EnhancedPlugin>>, config: PluginManagerConfig, ) -> EnhancedPluginManager

Creates a new EnhancedPluginManager with custom configuration.

Source

pub fn add_plugin(&mut self, plugin: Arc<dyn EnhancedPlugin>)

Adds a plugin after construction, re-sorting by priority.

The plugin is inserted and the entire list is re-sorted using a stable sort to maintain registration order for same-priority plugins.

Source

pub fn context(&self) -> &Arc<PluginContext>

Returns a reference to the shared plugin context.

The context is shared across all hook invocations and persists for the lifetime of this manager.

Source

pub fn plugin_count(&self) -> usize

Returns the number of registered plugins.

Source

pub fn plugin_names(&self) -> Vec<&str>

Returns the names of all registered plugins in execution order.

Source

pub async fn run_before_tool_call( &self, tool: Arc<dyn Tool>, args: Value, ctx: Arc<dyn CallbackContext>, ) -> Result<BeforeToolCallResult, AdkError>

Executes the before_tool_call pipeline across all plugins in priority order.

Each plugin receives the (possibly modified) arguments from the previous plugin. If a plugin returns ShortCircuit, the pipeline stops and the synthetic result is returned. If a plugin returns an error, the pipeline stops and the error is propagated.

§Arguments
  • tool - The tool about to be executed
  • args - The initial tool call arguments
  • ctx - The callback context for the current invocation
§Returns
  • Ok(BeforeToolCallResult::Continue(args)) — final modified arguments for tool execution
  • Ok(BeforeToolCallResult::ShortCircuit(result)) — synthetic result, skip tool execution
  • Err(e) — pipeline error, skip tool execution
Source

pub async fn run_after_tool_call( &self, tool: Arc<dyn Tool>, args: &Value, result: Value, ctx: Arc<dyn CallbackContext>, ) -> Result<AfterToolCallResult, AdkError>

Executes the after_tool_call pipeline across all plugins in priority order.

Each plugin receives the (possibly modified) result from the previous plugin. The args parameter contains the final modified arguments from the before-hook pipeline (not the original arguments).

§Arguments
  • tool - The tool that was executed
  • args - The final arguments used for tool execution (after before-hook modifications)
  • result - The initial tool execution result
  • ctx - The callback context for the current invocation
§Returns
  • Ok(AfterToolCallResult::Continue(result)) — final modified result
  • Err(e) — pipeline error
Source

pub async fn run_before_model_call( &self, request: LlmRequest, ctx: Arc<dyn CallbackContext>, ) -> Result<BeforeModelCallResult, AdkError>

Executes the before_model_call pipeline across all plugins in priority order.

Each plugin receives the (possibly modified) request from the previous plugin. If a plugin returns ShortCircuit, the pipeline stops and the synthetic response is returned. If a plugin returns an error, the pipeline stops and the error is propagated.

§Arguments
  • request - The initial LLM request
  • ctx - The callback context for the current invocation
§Returns
  • Ok(BeforeModelCallResult::Continue(request)) — final modified request for model call
  • Ok(BeforeModelCallResult::ShortCircuit(response)) — synthetic response, skip model call
  • Err(e) — pipeline error, skip model call
Source

pub async fn run_after_model_call( &self, response: LlmResponse, ctx: Arc<dyn CallbackContext>, ) -> Result<AfterModelCallResult, AdkError>

Executes the after_model_call pipeline across all plugins in priority order.

Each plugin receives the (possibly modified) response from the previous plugin. If a plugin returns an error, the pipeline stops and the error is propagated.

§Arguments
  • response - The initial LLM response
  • ctx - The callback context for the current invocation
§Returns
  • Ok(AfterModelCallResult::Continue(response)) — final modified response
  • Err(e) — pipeline error
Source

pub async fn close(&self)

Closes all plugins, ignoring individual close errors.

Each plugin’s close() method is called in sequence. Errors during close are logged but do not prevent other plugins from being closed.

Trait Implementations§

Source§

impl Debug for EnhancedPluginManager

Source§

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

Formats the value using the given formatter. 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> 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