Skip to main content

Reasoner

Trait Reasoner 

Source
pub trait Reasoner: Send + Sync {
    // Required methods
    fn reason<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        input: &'life1 AgentInput,
        ctx: &'life2 AgentContext,
    ) -> Pin<Box<dyn Future<Output = Result<ReasoningResult, AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn strategy(&self) -> ReasoningStrategy;

    // Provided methods
    fn supports_multi_step(&self) -> bool { ... }
    fn name(&self) -> &str { ... }
    fn description(&self) -> Option<&str> { ... }
}
Expand description

推理器 Trait

负责 Agent 的推理/思考过程

§示例

use mofa_kernel::agent::components::reasoner::{Reasoner, ReasoningResult};
use mofa_foundation::agent::components::reasoner::DirectReasoner;

// 使用 foundation 层提供的具体实现
let reasoner = DirectReasoner;
// 或者实现自定义 Reasoner
struct MyReasoner;

#[async_trait]
impl Reasoner for MyReasoner {
    async fn reason(&self, input: &AgentInput, ctx: &CoreAgentContext) -> AgentResult<ReasoningResult> {
        Ok(ReasoningResult {
            thoughts: vec![],
            decision: Decision::Respond { content: input.to_text() },
            confidence: 1.0,
        })
    }

    fn strategy(&self) -> ReasoningStrategy {
        ReasoningStrategy::Direct
    }
}

Required Methods§

Source

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

执行推理过程

Source

fn strategy(&self) -> ReasoningStrategy

获取推理策略

Provided Methods§

Source

fn supports_multi_step(&self) -> bool

是否支持多步推理

Source

fn name(&self) -> &str

推理器名称

Source

fn description(&self) -> Option<&str>

推理器描述

Implementors§