pub struct Plugin { /* private fields */ }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) -> Self
pub fn new(config: PluginConfig) -> Self
Create a new plugin from configuration.
Sourcepub fn on_user_message(&self) -> Option<&OnUserMessageCallback>
pub fn on_user_message(&self) -> Option<&OnUserMessageCallback>
Get the on_user_message callback if set.
Sourcepub fn on_event(&self) -> Option<&OnEventCallback>
pub fn on_event(&self) -> Option<&OnEventCallback>
Get the on_event callback if set.
Sourcepub fn before_run(&self) -> Option<&BeforeRunCallback>
pub fn before_run(&self) -> Option<&BeforeRunCallback>
Get the before_run callback if set.
Sourcepub fn after_run(&self) -> Option<&AfterRunCallback>
pub fn after_run(&self) -> Option<&AfterRunCallback>
Get the after_run callback if set.
Sourcepub fn before_agent(&self) -> Option<&BeforeAgentCallback>
pub fn before_agent(&self) -> Option<&BeforeAgentCallback>
Get the before_agent callback if set.
Sourcepub fn after_agent(&self) -> Option<&AfterAgentCallback>
pub fn after_agent(&self) -> Option<&AfterAgentCallback>
Get the after_agent callback if set.
Sourcepub fn before_model(&self) -> Option<&BeforeModelCallback>
pub fn before_model(&self) -> Option<&BeforeModelCallback>
Get the before_model callback if set.
Sourcepub fn after_model(&self) -> Option<&AfterModelCallback>
pub fn after_model(&self) -> Option<&AfterModelCallback>
Get the after_model callback if set.
Sourcepub fn on_model_error(&self) -> Option<&OnModelErrorCallback>
pub fn on_model_error(&self) -> Option<&OnModelErrorCallback>
Get the on_model_error callback if set.
Sourcepub fn before_tool(&self) -> Option<&BeforeToolCallback>
pub fn before_tool(&self) -> Option<&BeforeToolCallback>
Get the before_tool callback if set.
Sourcepub fn after_tool(&self) -> Option<&AfterToolCallback>
pub fn after_tool(&self) -> Option<&AfterToolCallback>
Get the after_tool callback if set.
Sourcepub fn on_tool_error(&self) -> Option<&OnToolErrorCallback>
pub fn on_tool_error(&self) -> Option<&OnToolErrorCallback>
Get the on_tool_error 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