use anyhow::{Context as _, Result};
use std::sync::Arc;
use swiftide::agents::Agent;
use tokio::sync::Mutex;
#[derive(Clone)]
pub struct RunningAgent {
pub agent: Arc<Mutex<Agent>>,
}
impl From<Agent> for RunningAgent {
fn from(agent: Agent) -> Self {
RunningAgent {
agent: Arc::new(Mutex::new(agent)),
}
}
}
impl RunningAgent {
pub async fn query(&self, query: &str) -> Result<()> {
self.agent
.lock()
.await
.query(query.to_string())
.await
.context("Failed to query agent")
}
pub async fn run(&self) -> Result<()> {
self.agent
.lock()
.await
.run()
.await
.context("Failed to run agent")
}
pub async fn stop(&self) {
self.agent.lock().await.stop("Stopped from kwaak").await;
}
}