Skip to main content

Agent

Trait Agent 

Source
pub trait Agent: Send + Sync {
    // Required method
    fn decide<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 ToolRegistry,
    ) -> Pin<Box<dyn Future<Output = Result<Decision, AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn prepare_context(&self, _ctx: &mut AgentContext, _messages: &[Message]) { ... }
    fn prepare_tools(
        &self,
        _ctx: &AgentContext,
        tools: &ToolRegistry,
    ) -> Vec<String> { ... }
    fn after_action(
        &self,
        _ctx: &mut AgentContext,
        _tool_name: &str,
        _output: &str,
    ) { ... }
}
Expand description

An agent that decides what tools to call given conversation history.

Lifecycle hooks (all have default no-op implementations):

  • prepare_context — called before each step to modify context
  • prepare_tools — called before each step to filter/modify tool set
  • after_action — called after tool execution with results

Required Methods§

Source

fn decide<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [Message], tools: &'life2 ToolRegistry, ) -> Pin<Box<dyn Future<Output = Result<Decision, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Given messages and available tools, decide what to do next.

Provided Methods§

Source

fn prepare_context(&self, _ctx: &mut AgentContext, _messages: &[Message])

Hook: modify context before each step. Default: no-op.

Source

fn prepare_tools( &self, _ctx: &AgentContext, tools: &ToolRegistry, ) -> Vec<String>

Hook: filter or reorder tools before each step. Returns tool names to include. Default: all tools.

Source

fn after_action(&self, _ctx: &mut AgentContext, _tool_name: &str, _output: &str)

Hook: called after tool execution with the tool name and output. Can modify context or messages. Default: no-op.

Implementors§