Skip to main content

Plugin

Struct Plugin 

Source
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

Source

pub fn new(config: PluginConfig) -> Self

Create a new plugin from configuration.

Source

pub fn name(&self) -> &str

Get the plugin name.

Source

pub fn on_user_message(&self) -> Option<&OnUserMessageCallback>

Get the on_user_message callback if set.

Source

pub fn on_event(&self) -> Option<&OnEventCallback>

Get the on_event callback if set.

Source

pub fn before_run(&self) -> Option<&BeforeRunCallback>

Get the before_run callback if set.

Source

pub fn after_run(&self) -> Option<&AfterRunCallback>

Get the after_run callback if set.

Source

pub fn before_agent(&self) -> Option<&BeforeAgentCallback>

Get the before_agent callback if set.

Source

pub fn after_agent(&self) -> Option<&AfterAgentCallback>

Get the after_agent callback if set.

Source

pub fn before_model(&self) -> Option<&BeforeModelCallback>

Get the before_model callback if set.

Source

pub fn after_model(&self) -> Option<&AfterModelCallback>

Get the after_model callback if set.

Source

pub fn on_model_error(&self) -> Option<&OnModelErrorCallback>

Get the on_model_error callback if set.

Source

pub fn before_tool(&self) -> Option<&BeforeToolCallback>

Get the before_tool callback if set.

Source

pub fn after_tool(&self) -> Option<&AfterToolCallback>

Get the after_tool callback if set.

Source

pub fn on_tool_error(&self) -> Option<&OnToolErrorCallback>

Get the on_tool_error callback if set.

Source

pub async fn close(&self)

Close the plugin, running cleanup if configured.

Trait Implementations§

Source§

impl Debug for Plugin

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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