Skip to main content

BaseAgent

Struct BaseAgent 

Source
pub struct BaseAgent {
    pub client: Client,
    pub config: Config,
    pub conversations: HashMap<String, Conversation>,
    pub name: String,
    pub description: String,
    pub system_prompt: Option<String>,
    pub llm_provider: Arc<dyn LLMProvider>,
    pub working_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>,
    pub episodic_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>,
    pub semantic_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>,
    pub tool_manager: ToolManager,
}
Expand description

The base agent implementation that provides common functionality.

Fields§

§client: Client§config: Config§conversations: HashMap<String, Conversation>§name: String§description: String§system_prompt: Option<String>§llm_provider: Arc<dyn LLMProvider>§working_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>§episodic_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>§semantic_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>§tool_manager: ToolManager

Implementations§

Source§

impl BaseAgent

Source

pub async fn preview_memory_debug( &self, conversation_id: &str, content: &str, use_memory: bool, ) -> MemoryDebugInfo

Source

pub async fn new( config: Config, name: &str, description: &str, llm_provider: Arc<dyn LLMProvider>, working_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>, episodic_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>, semantic_memory: Arc<Mutex<dyn MemoryProvider + Send + Sync>>, tool_manager: ToolManager, ) -> Result<Self, KowalskiError>

Source

pub fn set_temperature(&mut self, temperature: f32)

Source

pub fn set_system_prompt(&mut self, prompt: &str)

Source

pub async fn prepare_stream_turn( &mut self, conversation_id: &str, content: &str, role: Option<Role>, ) -> Result<(String, Vec<Message>, Arc<dyn LLMProvider>), KowalskiError>

Same memory + user turn as Agent::chat_with_history, but returns owned messages for crate::llm::LLMProvider::chat_stream without calling the LLM (caller streams, then should Self::add_message with role assistant for the full reply).

Source

pub async fn prepare_stream_turn_with_options( &mut self, conversation_id: &str, content: &str, role: Option<Role>, use_memory: bool, ) -> Result<(String, Vec<Message>, Arc<dyn LLMProvider>), KowalskiError>

Source

pub async fn chat_with_tools_with_options( &mut self, conversation_id: &str, user_input: &str, use_memory: bool, ) -> Result<String, KowalskiError>

Like Agent::chat_with_tools but emits token deltas over token_tx only for the first LLM completion after at least one tool execution in this request (final natural answer).

Source

pub async fn chat_with_tools_stream_final( &mut self, conversation_id: &str, user_input: &str, token_tx: &Sender<String>, ) -> Result<String, KowalskiError>

Source

pub async fn chat_with_tools_stream_final_with_options( &mut self, conversation_id: &str, user_input: &str, token_tx: &Sender<String>, use_memory: bool, ) -> Result<String, KowalskiError>

Source§

impl BaseAgent

Source

pub async fn chat_with_history_with_options( &mut self, conversation_id: &str, content: &str, role: Option<Role>, use_memory: bool, ) -> Result<String, KowalskiError>

Trait Implementations§

Source§

impl Agent for BaseAgent

Source§

fn new<'async_trait>( config: Config, ) -> Pin<Box<dyn Future<Output = Result<Self, KowalskiError>> + Send + 'async_trait>>
where Self: 'async_trait,

Creates a new agent with the specified configuration.
Source§

fn start_conversation(&mut self, model: &str) -> String

Starts a new conversation
Source§

fn get_conversation(&self, id: &str) -> Option<&Conversation>

Gets a conversation by ID
Source§

fn list_conversations(&self) -> Vec<&Conversation>

Lists all conversations
Source§

fn delete_conversation(&mut self, id: &str) -> bool

Deletes a conversation
Source§

fn chat_with_history<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, conversation_id: &'life1 str, content: &'life2 str, role: Option<Role>, ) -> Pin<Box<dyn Future<Output = Result<String, KowalskiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Chats with history (model messages) for the given conversation.
Source§

fn process_stream_response<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, conversation_id: &'life1 str, chunk: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Message>, KowalskiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Processes a stream response
Source§

fn add_message<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, conversation_id: &'life1 str, role: &'life2 str, content: &'life3 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Adds a message to a conversation
Source§

fn export_conversation(&self, id: &str) -> Result<String, KowalskiError>

Exports a conversation to a JSON string
Source§

fn import_conversation( &mut self, json_str: &str, ) -> Result<String, KowalskiError>

Imports a conversation from a JSON string, returns the new conversation ID
Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Gets the agent’s description
Source§

fn as_any(&self) -> &dyn Any

Source§

fn execute_tool<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _tool_name: &'life1 str, _tool_input: &'life2 Value, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, KowalskiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Executes a tool with the given name and input.
Source§

fn chat_with_tools<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, conversation_id: &'life1 str, user_input: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<String, KowalskiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Chat with the agent using ReAct-style tool calling
Source§

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

Lists tools available to this agent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T