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: ToolManagerImplementations§
Source§impl BaseAgent
impl BaseAgent
pub async fn preview_memory_debug( &self, conversation_id: &str, content: &str, use_memory: bool, ) -> MemoryDebugInfo
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>
pub fn set_temperature(&mut self, temperature: f32)
pub fn set_system_prompt(&mut self, prompt: &str)
Sourcepub async fn prepare_stream_turn(
&mut self,
conversation_id: &str,
content: &str,
role: Option<Role>,
) -> Result<(String, Vec<Message>, Arc<dyn LLMProvider>), KowalskiError>
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).
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>
Sourcepub async fn chat_with_tools_with_options(
&mut self,
conversation_id: &str,
user_input: &str,
use_memory: bool,
) -> Result<String, KowalskiError>
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).
pub async fn chat_with_tools_stream_final( &mut self, conversation_id: &str, user_input: &str, token_tx: &Sender<String>, ) -> Result<String, KowalskiError>
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>
Trait Implementations§
Source§impl Agent for BaseAgent
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,
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
fn start_conversation(&mut self, model: &str) -> String
Starts a new conversation
Source§fn get_conversation(&self, id: &str) -> Option<&Conversation>
fn get_conversation(&self, id: &str) -> Option<&Conversation>
Gets a conversation by ID
Source§fn list_conversations(&self) -> Vec<&Conversation>
fn list_conversations(&self) -> Vec<&Conversation>
Lists all conversations
Source§fn delete_conversation(&mut self, id: &str) -> bool
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,
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,
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,
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>
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>
fn import_conversation( &mut self, json_str: &str, ) -> Result<String, KowalskiError>
Imports a conversation from a JSON string, returns the new conversation ID
fn name(&self) -> &str
Source§fn description(&self) -> &str
fn description(&self) -> &str
Gets the agent’s description
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,
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,
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
Auto Trait Implementations§
impl Freeze for BaseAgent
impl !RefUnwindSafe for BaseAgent
impl Send for BaseAgent
impl Sync for BaseAgent
impl Unpin for BaseAgent
impl UnsafeUnpin for BaseAgent
impl !UnwindSafe for BaseAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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