pub struct PluginManager { /* private fields */ }Expand description
The registered plugins and the bound on closing them.
Implementations§
Source§impl PluginManager
impl PluginManager
Sourcepub fn new(
plugins: Vec<Plugin>,
close_timeout: Duration,
) -> Result<Self, AgentError>
pub fn new( plugins: Vec<Plugin>, close_timeout: Duration, ) -> Result<Self, AgentError>
Registers plugins in order; fails only on a duplicate plugin name.
Sourcepub fn has_plugins(&self) -> bool
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())).
Sourcepub async fn run_on_user_message(
&self,
ctx: InvocationContext,
msg: Content,
) -> Result<Option<Content>, AgentError>
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.
Sourcepub async fn run_before_run(
&self,
ctx: InvocationContext,
) -> Result<Option<Content>, AgentError>
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.
Sourcepub async fn run_after_run(&self, ctx: InvocationContext)
pub async fn run_after_run(&self, ctx: InvocationContext)
Runs the after-run callbacks: every plugin’s callback, in order.
Sourcepub async fn run_on_event(
&self,
ctx: InvocationContext,
event: Event,
) -> Result<Option<Event>, AgentError>
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.
Sourcepub async fn run_before_agent(
&self,
ctx: Context,
) -> Result<Option<Content>, AgentError>
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.
Sourcepub async fn run_after_agent(
&self,
ctx: Context,
) -> Result<Option<Content>, AgentError>
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.
Sourcepub fn run_on_agent_error(
&self,
ctx: Context,
agent: Arc<dyn Agent>,
err: &AgentError,
)
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.
Sourcepub async fn run_before_model(
&self,
ctx: Context,
req: LlmRequest,
) -> (LlmRequest, Result<Option<LlmResponse>, AgentError>)
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.
Sourcepub async fn run_after_model(
&self,
ctx: Context,
resp: LlmResponse,
err: Option<Arc<ModelError>>,
) -> (LlmResponse, Result<Option<LlmResponse>, AgentError>)
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.
Sourcepub async fn run_on_model_error(
&self,
ctx: Context,
req: LlmRequest,
err: Arc<ModelError>,
) -> Result<Option<LlmResponse>, AgentError>
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.
Sourcepub 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>)
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub async fn close(&self) -> Result<(), AgentError>
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.