Skip to main content

PluginManager

Struct PluginManager 

Source
pub struct PluginManager { /* private fields */ }
Expand description

The registered plugins and the bound on closing them.

Implementations§

Source§

impl PluginManager

Source

pub fn new( plugins: Vec<Plugin>, close_timeout: Duration, ) -> Result<Self, AgentError>

Registers plugins in order; fails only on a duplicate plugin name.

Source

pub fn has_plugins(&self) -> bool

Whether any plugin is registered. A missing manager is None at the call site (pm.is_some_and(|m| m.has_plugins())).

Source

pub async fn run_on_user_message( &self, ctx: InvocationContext, msg: Content, ) -> Result<Option<Content>, AgentError>

Runs the on-user-message callbacks; the first Some content replaces the user message.

Source

pub async fn run_before_run( &self, ctx: InvocationContext, ) -> Result<Option<Content>, AgentError>

Runs the before-run callbacks; the first Some content ends the run early.

Source

pub async fn run_after_run(&self, ctx: InvocationContext)

Runs the after-run callbacks: every plugin’s callback, in order.

Source

pub async fn run_on_event( &self, ctx: InvocationContext, event: Event, ) -> Result<Option<Event>, AgentError>

Runs the on-event callbacks; the first Some event replaces the event.

Source

pub async fn run_before_agent( &self, ctx: Context, ) -> Result<Option<Content>, AgentError>

Runs the before-agent callbacks; the first Some content skips the agent run.

Source

pub async fn run_after_agent( &self, ctx: Context, ) -> Result<Option<Content>, AgentError>

Runs the after-agent callbacks; the first Some content is returned as the agent’s output.

Source

pub fn run_on_agent_error( &self, ctx: Context, agent: Arc<dyn Agent>, err: &AgentError, )

Notifies every plugin, in registration order, that err escaped agent’s run. Best-effort notification: no plugin can suppress the error. A panic from one callback is caught (and recorded on the current span as plugin "<name>" OnAgentErrorCallback panicked: <panic>), so the remaining callbacks still run.

Source

pub async fn run_before_model( &self, ctx: Context, req: LlmRequest, ) -> (LlmRequest, Result<Option<LlmResponse>, AgentError>)

Runs the before-model callbacks: the request is threaded through every callback and always handed back.

Source

pub async fn run_after_model( &self, ctx: Context, resp: LlmResponse, err: Option<Arc<ModelError>>, ) -> (LlmResponse, Result<Option<LlmResponse>, AgentError>)

Runs the after-model callbacks: the response is threaded through every callback (each sees the previous callback’s response) and always handed back.

Source

pub async fn run_on_model_error( &self, ctx: Context, req: LlmRequest, err: Arc<ModelError>, ) -> Result<Option<LlmResponse>, AgentError>

Runs the on-model-error callbacks; the first Some response replaces the failed call.

Source

pub async fn run_before_tool( &self, ctx: Context, tool: Arc<dyn Tool>, args: Map<String, Value>, ) -> (Map<String, Value>, Result<Option<Map<String, Value>>, AgentError>)

Runs the before-tool callbacks: the arguments are threaded through every callback (each sees the previous callback’s arguments) and always handed back.

Source

pub async fn run_after_tool( &self, ctx: Context, tool: Arc<dyn Tool>, args: Map<String, Value>, result: Map<String, Value>, err: Option<Arc<ToolError>>, ) -> Result<Option<Map<String, Value>>, AgentError>

Runs the after-tool callbacks; the first Some result replaces the tool’s result.

Source

pub async fn run_on_tool_error( &self, ctx: Context, tool: Arc<dyn Tool>, args: Map<String, Value>, err: Arc<ToolError>, ) -> Result<Option<Map<String, Value>>, AgentError>

Runs the on-tool-error callbacks; the first Some result replaces the failed call.

Source

pub async fn close(&self) -> Result<(), AgentError>

Closes every plugin, collecting error closing plugin '<name>': <err>, and returns failed to close plugins: [e1 e2 …]. A close_timeout above zero bounds each close function (an elapsed one records close timed out after {close_timeout:?}); zero means no bound.

Trait Implementations§

Source§

impl Debug for PluginManager

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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