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 !RefUnwindSafe for Plugin
impl !UnwindSafe for Plugin
impl Forget for Plugin
impl Freeze for Pluginwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>: Freeze,
*const dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send is !null: Freeze,
PhantomData<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Freeze,
impl Move for Plugin
impl Send for Pluginwhere
RawVecInner: Send,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>: Send,
BoxRaw<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Send,
impl Sync for Pluginwhere
RawVecInner: Sync,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>: Sync,
BoxRaw<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Sync,
impl Unpin for Pluginwhere
*const u8 is !null: Unpin,
Box<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>: Unpin,
Box<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: Unpin,
impl UnsafeUnpin for Pluginwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn InvocationContext>, Content) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn InvocationContext>, Event) -> Pin<Box<dyn Future<Output = Result<Option<Event>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn InvocationContext>) -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, LlmRequest, String) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>: UnsafeUnpin,
*const dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Sync + Send>: UnsafeUnpin,
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