pub(crate) struct ChatAgent {
chat_history: Arc<Mutex<ChatHistory>>,
ui_notifications: Arc<UnboundedSender<Notification>>,
incoming: Option<Incoming>,
}Expand description
State of the agent-running part of the llimorse-based chat application
Fields§
§chat_history: Arc<Mutex<ChatHistory>>The chat history as shared with the agent
ui_notifications: Arc<UnboundedSender<Notification>>Notify the UI to redraw
incoming: Option<Incoming>Notifications from the application
Generally Some(_), but we need to .take() it during tool call execution so we can use
this mutably while the tool call executor has &self borrowed.
Implementations§
Source§impl ChatAgent
impl ChatAgent
Sourcepub fn new(
chat_history: Arc<Mutex<ChatHistory>>,
notifications: UnboundedReceiver<Notification>,
ui_notifications: Arc<UnboundedSender<Notification>>,
) -> Self
pub fn new( chat_history: Arc<Mutex<ChatHistory>>, notifications: UnboundedReceiver<Notification>, ui_notifications: Arc<UnboundedSender<Notification>>, ) -> Self
Create a new instance.
Sourcepub async fn run(&mut self, agent: Agent) -> Result<()>
pub async fn run(&mut self, agent: Agent) -> Result<()>
Run agent requests in a loop until the exit flag is set (or an error occurs).
Will itself set the exit flag before returning.
Sourceasync fn process_notifications(&mut self) -> bool
async fn process_notifications(&mut self) -> bool
Process incoming notifications until finding a prompt, a continue, or an exit.
Return false if the channel is closed (or an exit event is received).
The caller must submit self.queued_messages immediately (because this function
ignores ForceSubmitQueued, assuming the caller will do so).
Sourcefn process_available_notifications(&mut self) -> bool
fn process_available_notifications(&mut self) -> bool
Process all available incoming notifications (non-blocking)
Return false if an exit event is received.
The caller must submit self.queued_messages immediately (because this function
ignores ForceSubmitQueued, assuming the caller will do so).
Sourcefn submit_queued_user_messages(&mut self, agent: &mut Agent) -> bool
fn submit_queued_user_messages(&mut self, agent: &mut Agent) -> bool
Push all messages currently in self.queued_messages onto the agent/chat history.
Return if there were any messages.
This does not yet submit a request to the agent.
Sourcefn can_continue(history: &[ChatMessage]) -> bool
fn can_continue(history: &[ChatMessage]) -> bool
Whether a history can be submitted without a new user message: it must top out on a tool result (e.g. an interrupted session) or a user message the model has not answered yet.
Sourceasync fn do_run(&mut self, agent: Agent) -> Result<()>
async fn do_run(&mut self, agent: Agent) -> Result<()>
Run agent requests in a loop until the exit flag is set (or an error occurs).
Sourcefn process_chunk(&self, chunk: StreamingChunk)
fn process_chunk(&self, chunk: StreamingChunk)
Process the incoming chunk from the LLM (i.e. append it to the history).
Sourcefn push_history(&self, string: &str, kind: HistoryEntryType)
fn push_history(&self, string: &str, kind: HistoryEntryType)
Push the given string into the chat history, processing newlines