pub struct PluginManager { /* private fields */ }plugin only.Expand description
Manages a collection of plugins and coordinates callback execution.
The PluginManager runs callbacks from all registered plugins in order. For callbacks that can modify data (like on_user_message), the first plugin to return a modification wins.
§Example
use adk_plugin::{Plugin, PluginManager, PluginConfig};
let plugins = vec![
Plugin::new(PluginConfig {
name: "logging".to_string(),
on_event: Some(log_events()),
..Default::default()
}),
Plugin::new(PluginConfig {
name: "metrics".to_string(),
before_run: Some(start_timer()),
after_run: Some(stop_timer()),
..Default::default()
}),
];
let manager = PluginManager::new(plugins);Implementations§
Source§impl PluginManager
impl PluginManager
Sourcepub fn new(plugins: Vec<Plugin>) -> PluginManager
pub fn new(plugins: Vec<Plugin>) -> PluginManager
Create a new plugin manager with the given plugins.
Sourcepub fn with_config(
plugins: Vec<Plugin>,
config: PluginManagerConfig,
) -> PluginManager
pub fn with_config( plugins: Vec<Plugin>, config: PluginManagerConfig, ) -> PluginManager
Create a new plugin manager with custom configuration.
Sourcepub fn plugin_count(&self) -> usize
pub fn plugin_count(&self) -> usize
Get the number of registered plugins.
Sourcepub fn plugin_names(&self) -> Vec<&str>
pub fn plugin_names(&self) -> Vec<&str>
Get plugin names.
Sourcepub async fn run_on_user_message(
&self,
ctx: Arc<dyn InvocationContext>,
content: Content,
) -> Result<Option<Content>, AdkError>
pub async fn run_on_user_message( &self, ctx: Arc<dyn InvocationContext>, content: Content, ) -> Result<Option<Content>, AdkError>
Run on_user_message callbacks from all plugins.
Returns the modified content if any plugin modified it.
Sourcepub async fn run_on_event(
&self,
ctx: Arc<dyn InvocationContext>,
event: Event,
) -> Result<Option<Event>, AdkError>
pub async fn run_on_event( &self, ctx: Arc<dyn InvocationContext>, event: Event, ) -> Result<Option<Event>, AdkError>
Run on_event callbacks from all plugins.
Returns the modified event if any plugin modified it.
Sourcepub async fn run_before_run(
&self,
ctx: Arc<dyn InvocationContext>,
) -> Result<Option<Content>, AdkError>
pub async fn run_before_run( &self, ctx: Arc<dyn InvocationContext>, ) -> Result<Option<Content>, AdkError>
Run before_run callbacks from all plugins.
If any plugin returns content, the run should be skipped.
Sourcepub async fn run_after_run(&self, ctx: Arc<dyn InvocationContext>)
pub async fn run_after_run(&self, ctx: Arc<dyn InvocationContext>)
Run after_run callbacks from all plugins.
This does NOT emit events - it’s for cleanup/metrics only.
Sourcepub async fn run_before_agent(
&self,
ctx: Arc<dyn CallbackContext>,
) -> Result<Option<Content>, AdkError>
pub async fn run_before_agent( &self, ctx: Arc<dyn CallbackContext>, ) -> Result<Option<Content>, AdkError>
Run before_agent callbacks from all plugins.
If any plugin returns content, the agent run should be skipped.
Sourcepub async fn run_after_agent(
&self,
ctx: Arc<dyn CallbackContext>,
) -> Result<Option<Content>, AdkError>
pub async fn run_after_agent( &self, ctx: Arc<dyn CallbackContext>, ) -> Result<Option<Content>, AdkError>
Run after_agent callbacks from all plugins.
Sourcepub async fn run_before_model(
&self,
ctx: Arc<dyn CallbackContext>,
request: LlmRequest,
) -> Result<BeforeModelResult, AdkError>
pub async fn run_before_model( &self, ctx: Arc<dyn CallbackContext>, request: LlmRequest, ) -> Result<BeforeModelResult, AdkError>
Run before_model callbacks from all plugins.
Callbacks can modify the request or skip the model call.
Sourcepub async fn run_after_model(
&self,
ctx: Arc<dyn CallbackContext>,
response: LlmResponse,
) -> Result<Option<LlmResponse>, AdkError>
pub async fn run_after_model( &self, ctx: Arc<dyn CallbackContext>, response: LlmResponse, ) -> Result<Option<LlmResponse>, AdkError>
Run after_model callbacks from all plugins.
Sourcepub async fn run_on_model_error(
&self,
ctx: Arc<dyn CallbackContext>,
request: LlmRequest,
error: String,
) -> Result<Option<LlmResponse>, AdkError>
pub async fn run_on_model_error( &self, ctx: Arc<dyn CallbackContext>, request: LlmRequest, error: String, ) -> Result<Option<LlmResponse>, AdkError>
Run on_model_error callbacks from all plugins.
Sourcepub async fn run_before_tool(
&self,
ctx: Arc<dyn CallbackContext>,
) -> Result<Option<Content>, AdkError>
pub async fn run_before_tool( &self, ctx: Arc<dyn CallbackContext>, ) -> Result<Option<Content>, AdkError>
Run before_tool callbacks from all plugins.
Sourcepub async fn run_after_tool(
&self,
ctx: Arc<dyn CallbackContext>,
) -> Result<Option<Content>, AdkError>
pub async fn run_after_tool( &self, ctx: Arc<dyn CallbackContext>, ) -> Result<Option<Content>, AdkError>
Run after_tool callbacks from all plugins.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PluginManager
impl !UnwindSafe for PluginManager
impl Freeze for PluginManager
impl Send for PluginManager
impl Sync for PluginManager
impl Unpin for PluginManager
impl UnsafeUnpin for PluginManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.