Trait AgentContext

Source
pub trait AgentContext: Send + Sync {
    // Required methods
    fn next_completion<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ChatMessage>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn current_new_messages<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn add_messages<'life0, 'async_trait>(
        &'life0 self,
        item: Vec<ChatMessage>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn add_message<'life0, 'async_trait>(
        &'life0 self,
        item: ChatMessage,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn exec_cmd<'life0, 'life1, 'async_trait>(
        &'life0 self,
        cmd: &'life1 Command,
    ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn executor(&self) -> &Arc<dyn ToolExecutor>;
    fn history<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn redrive<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn has_received_feedback<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tool_call: &'life1 ToolCall,
    ) -> Pin<Box<dyn Future<Output = Option<ToolFeedback>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn feedback_received<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        tool_call: &'life1 ToolCall,
        feedback: &'life2 ToolFeedback,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Acts as the interface to the external world and manages messages for completion

Required Methods§

Source

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ChatMessage>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List of all messages for this agent

Used as main source for the next completion and expects all messages to be returned if new messages are present.

Once this method has been called, there should not be new messages

TODO: Figure out a nice way to return a reference instead while still supporting i.e. mutexes

Source

fn current_new_messages<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists only the new messages after calling new_completion

Source

fn add_messages<'life0, 'async_trait>( &'life0 self, item: Vec<ChatMessage>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add messages for the next completion

Source

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add messages for the next completion

Source

fn exec_cmd<'life0, 'life1, 'async_trait>( &'life0 self, cmd: &'life1 Command, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

👎Deprecated: use executor instead

Execute a command if the context supports it

Deprecated: use executor instead to access the executor directly

Source

fn executor(&self) -> &Arc<dyn ToolExecutor>

Source

fn history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

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

Pops the last messages up until the last completion

LLMs failing completion for various reasons is unfortunately a common occurrence This gives a way to redrive the last completion in a generic way

Source

fn has_received_feedback<'life0, 'life1, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, ) -> Pin<Box<dyn Future<Output = Option<ToolFeedback>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Tools that require feedback or approval (i.e. from a human) can use this to check if the feedback is received

Source

fn feedback_received<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, feedback: &'life2 ToolFeedback, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Trait Implementations§

Source§

impl AgentContext for &dyn AgentContext

Source§

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ChatMessage>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List of all messages for this agent Read more
Source§

fn current_new_messages<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists only the new messages after calling new_completion
Source§

fn add_messages<'life0, 'async_trait>( &'life0 self, item: Vec<ChatMessage>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add messages for the next completion
Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add messages for the next completion
Source§

fn exec_cmd<'life0, 'life1, 'async_trait>( &'life0 self, cmd: &'life1 Command, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

👎Deprecated: use executor instead
Execute a command if the context supports it Read more
Source§

fn executor(&self) -> &Arc<dyn ToolExecutor>

Source§

fn history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Pops the last messages up until the last completion Read more
Source§

fn has_received_feedback<'life0, 'life1, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, ) -> Pin<Box<dyn Future<Output = Option<ToolFeedback>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Tools that require feedback or approval (i.e. from a human) can use this to check if the feedback is received
Source§

fn feedback_received<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, feedback: &'life2 ToolFeedback, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

impl AgentContext for Box<dyn AgentContext>

Source§

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ChatMessage>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List of all messages for this agent Read more
Source§

fn current_new_messages<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists only the new messages after calling new_completion
Source§

fn add_messages<'life0, 'async_trait>( &'life0 self, item: Vec<ChatMessage>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add messages for the next completion
Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add messages for the next completion
Source§

fn exec_cmd<'life0, 'life1, 'async_trait>( &'life0 self, cmd: &'life1 Command, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

👎Deprecated: use executor instead
Execute a command if the context supports it Read more
Source§

fn executor(&self) -> &Arc<dyn ToolExecutor>

Source§

fn history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Pops the last messages up until the last completion Read more
Source§

fn has_received_feedback<'life0, 'life1, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, ) -> Pin<Box<dyn Future<Output = Option<ToolFeedback>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Tools that require feedback or approval (i.e. from a human) can use this to check if the feedback is received
Source§

fn feedback_received<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, feedback: &'life2 ToolFeedback, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Implementations on Foreign Types§

Source§

impl AgentContext for ()

Convenience implementation for empty agent context

Errors if tools attempt to execute commands

Source§

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ChatMessage>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn current_new_messages<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn add_messages<'life0, 'async_trait>( &'life0 self, _item: Vec<ChatMessage>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn add_message<'life0, 'async_trait>( &'life0 self, _item: ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn exec_cmd<'life0, 'life1, 'async_trait>( &'life0 self, _cmd: &'life1 Command, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

👎Deprecated: use executor instead
Source§

fn executor(&self) -> &Arc<dyn ToolExecutor>

Source§

fn history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Source§

fn has_received_feedback<'life0, 'life1, 'async_trait>( &'life0 self, _tool_call: &'life1 ToolCall, ) -> Pin<Box<dyn Future<Output = Option<ToolFeedback>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn feedback_received<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _tool_call: &'life1 ToolCall, _feedback: &'life2 ToolFeedback, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

impl AgentContext for Box<dyn AgentContext>

Source§

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ChatMessage>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn current_new_messages<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn add_messages<'life0, 'async_trait>( &'life0 self, item: Vec<ChatMessage>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn exec_cmd<'life0, 'life1, 'async_trait>( &'life0 self, cmd: &'life1 Command, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

👎Deprecated: use executor instead
Source§

fn executor(&self) -> &Arc<dyn ToolExecutor>

Source§

fn history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Source§

fn has_received_feedback<'life0, 'life1, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, ) -> Pin<Box<dyn Future<Output = Option<ToolFeedback>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn feedback_received<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_call: &'life1 ToolCall, feedback: &'life2 ToolFeedback, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Implementors§