swiftide::traits

Trait AgentContext

Source
pub trait AgentContext: Send + Sync {
    // Required methods
    fn next_completion<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn current_new_messages<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Vec<ChatMessage>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn add_messages<'life0, 'async_trait>(
        &'life0 self,
        item: Vec<ChatMessage>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn add_message<'life0, 'async_trait>(
        &'life0 self,
        item: ChatMessage,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: '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 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn history<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Vec<ChatMessage>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn redrive<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: '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 = Option<Vec<ChatMessage>>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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 = Vec<ChatMessage>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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 = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Add messages for the next completion

Source

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Execute a command if the context supports it

Source

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

Source

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

Trait Implementations§

Source§

impl AgentContext for &dyn AgentContext

Source§

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>
where 'life0: 'async_trait, &dyn AgentContext: '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 = Vec<ChatMessage>> + Send + 'async_trait>>
where 'life0: 'async_trait, &dyn AgentContext: '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 = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, &dyn AgentContext: 'async_trait,

Add messages for the next completion
Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, &dyn AgentContext: '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 'life0: 'async_trait, 'life1: 'async_trait, &dyn AgentContext: 'async_trait,

Execute a command if the context supports it
Source§

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

Source§

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

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

impl AgentContext for Box<dyn AgentContext>

Source§

fn next_completion<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>
where 'life0: 'async_trait, Box<dyn AgentContext>: '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 = Vec<ChatMessage>> + Send + 'async_trait>>
where 'life0: 'async_trait, Box<dyn AgentContext>: '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 = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Box<dyn AgentContext>: 'async_trait,

Add messages for the next completion
Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Box<dyn AgentContext>: '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 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn AgentContext>: 'async_trait,

Execute a command if the context supports it
Source§

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

Source§

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

Pops the last messages up until the last completion Read more

Implementations on Foreign Types§

Source§

impl AgentContext for Box<dyn AgentContext>

Source§

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

Source§

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

Source§

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

Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Box<dyn AgentContext>: '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 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn AgentContext>: 'async_trait,

Source§

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

Source§

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

Source§

impl AgentContext for Arc<dyn AgentContext>

Source§

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

Source§

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

Source§

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

Source§

fn add_message<'life0, 'async_trait>( &'life0 self, item: ChatMessage, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Arc<dyn AgentContext>: '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 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn AgentContext>: 'async_trait,

Source§

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

Source§

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

Implementors§