pub struct Plugin { /* private fields */ }Available on crate feature
plugin only.Expand description
A Plugin bundles related callbacks for extending agent behavior.
Plugins are registered with a PluginManager which coordinates callback execution across all registered plugins.
§Example
ⓘ
use adk_plugin::{Plugin, PluginConfig};
// Create a caching plugin
let cache_plugin = Plugin::new(PluginConfig {
name: "cache".to_string(),
before_model: Some(Box::new(|ctx, request| {
Box::pin(async move {
// Check cache for this request
if let Some(cached) = check_cache(&request).await {
return Ok(BeforeModelResult::Skip(cached));
}
Ok(BeforeModelResult::Continue(request))
})
})),
after_model: Some(Box::new(|ctx, response| {
Box::pin(async move {
// Store response in cache
store_in_cache(&response).await;
Ok(None)
})
})),
..Default::default()
});Implementations§
Source§impl Plugin
impl Plugin
Sourcepub fn new(config: PluginConfig) -> Plugin
pub fn new(config: PluginConfig) -> Plugin
Create a new plugin from configuration.
Sourcepub fn on_user_message(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
pub fn on_user_message( &self, ) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
Get the on_user_message callback if set.
Sourcepub fn on_event(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Send + Sync>>
pub fn on_event( &self, ) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Send + Sync>>
Get the on_event callback if set.
Sourcepub fn before_run(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
pub fn before_run( &self, ) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
Get the before_run callback if set.
Sourcepub fn after_run(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>
pub fn after_run( &self, ) -> Option<&Box<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>>
Get the after_run callback if set.
Sourcepub fn before_agent(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
pub fn before_agent( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
Get the before_agent callback if set.
Sourcepub fn after_agent(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
pub fn after_agent( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
Get the after_agent callback if set.
Sourcepub fn before_model(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Send + Sync>>
pub fn before_model( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Send + Sync>>
Get the before_model callback if set.
Sourcepub fn after_model(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Send + Sync>>
pub fn after_model( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Send + Sync>>
Get the after_model callback if set.
Sourcepub fn on_model_error(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Send + Sync>>
pub fn on_model_error( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Send + Sync>>
Get the on_model_error callback if set.
Sourcepub fn before_tool(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
pub fn before_tool( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
Get the before_tool callback if set.
Sourcepub fn after_tool(
&self,
) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
pub fn after_tool( &self, ) -> Option<&Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Send + Sync>>
Get the after_tool callback if set.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Plugin
impl !RefUnwindSafe for Plugin
impl Send for Plugin
impl Sync for Plugin
impl Unpin for Plugin
impl UnsafeUnpin for Plugin
impl !UnwindSafe for Plugin
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
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestCreates a shared type from an unshared type.