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 = AgentResult<AgentInput>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn pre_context<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn post_response<'life0, 'life1, 'async_trait>(
&'life0 self,
output: AgentOutput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentOutput>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn post_process<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
插件接口
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
获取插件描述
Sourcefn metadata(&self) -> PluginMetadata
fn metadata(&self) -> PluginMetadata
获取插件元数据
Provided Methods§
Sourcefn pre_request<'life0, 'life1, 'async_trait>(
&'life0 self,
input: AgentInput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentInput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn pre_request<'life0, 'life1, 'async_trait>(
&'life0 self,
input: AgentInput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentInput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
在请求处理前执行 可以修改输入内容
Sourcefn pre_context<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn pre_context<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
在上下文组装前执行 可以动态修改上下文
Sourcefn post_response<'life0, 'life1, 'async_trait>(
&'life0 self,
output: AgentOutput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn post_response<'life0, 'life1, 'async_trait>(
&'life0 self,
output: AgentOutput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<AgentOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
在LLM响应后执行 可以修改LLM返回的结果
Sourcefn post_process<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn post_process<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = AgentResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
在整个流程完成后执行 可以进行清理或后续处理