Skip to main content

EnhancedPluginManager

Struct EnhancedPluginManager 

Source
pub struct EnhancedPluginManager { /* private fields */ }
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.

Each invocation’s hooks share one PluginContext of their own (invocation_context); the manager keeps the 1024 most recently used and drops the least recently used beyond that.

§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>>) -> Self

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, ) -> Self

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 the per-agent plugin context.

Every invocation of the agent shares it, and it lives as long as the manager. Hooks receive their invocation’s context instead and reach this one through PluginContext::shared.

Source

pub fn invocation_context( &self, ctx: &dyn ReadonlyContext, ) -> Arc<PluginContext> ⓘ

Returns the plugin context of the invocation ctx belongs to, creating it on first use.

An invocation is identified by its app, user, session, and invocation id; every hook of the invocation receives this context. Its shared context is context. Implements spec 3.1 §12 phase 0 (PluginContext per invocation).

§Examples
ⓘ
let manager = EnhancedPluginManager::new(plugins);
let alice = manager.invocation_context(alice_ctx.as_ref());
let bob = manager.invocation_context(bob_ctx.as_ref());
assert!(!Arc::ptr_eq(&alice, &bob));
assert!(std::ptr::eq(alice.shared(), manager.context().as_ref()));
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>

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>

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>

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>

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

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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