Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn metadata(&self) -> PluginMetadata;

    // Provided methods
    fn pre_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        input: AgentInput,
        _ctx: &'life1 AgentContext,
    ) -> Pin<Box<dyn Future<Output = Result<AgentInput, AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn pre_context<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 AgentContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn post_response<'life0, 'life1, 'async_trait>(
        &'life0 self,
        output: AgentOutput,
        _ctx: &'life1 AgentContext,
    ) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn post_process<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 AgentContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

插件接口

Required Methods§

Source

fn name(&self) -> &str

获取插件名称

Source

fn description(&self) -> &str

获取插件描述

Source

fn metadata(&self) -> PluginMetadata

获取插件元数据

Provided Methods§

Source

fn pre_request<'life0, 'life1, 'async_trait>( &'life0 self, input: AgentInput, _ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = Result<AgentInput, AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

在请求处理前执行 可以修改输入内容

Source

fn pre_context<'life0, 'life1, 'async_trait>( &'life0 self, _ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

在上下文组装前执行 可以动态修改上下文

Source

fn post_response<'life0, 'life1, 'async_trait>( &'life0 self, output: AgentOutput, _ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

在LLM响应后执行 可以修改LLM返回的结果

Source

fn post_process<'life0, 'life1, 'async_trait>( &'life0 self, _ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

在整个流程完成后执行 可以进行清理或后续处理

Implementations on Foreign Types§

Source§

impl Plugin for CustomFunctionPlugin

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn metadata(&self) -> PluginMetadata

Source§

fn pre_request<'life0, 'life1, 'async_trait>( &'life0 self, input: AgentInput, ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = Result<AgentInput, AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, CustomFunctionPlugin: 'async_trait,

Source§

impl Plugin for HttpPlugin

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn metadata(&self) -> PluginMetadata

Source§

fn pre_context<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, HttpPlugin: 'async_trait,

Implementors§