use crate::types::{AgentOutput, Context, Inputs};
use std::future::Future;
use tokio::sync::mpsc;
#[derive(Clone)]
pub struct LogSender {
tx: mpsc::Sender<String>,
}
impl LogSender {
pub(crate) fn new(tx: mpsc::Sender<String>) -> Self {
Self { tx }
}
pub async fn send(&self, msg: impl Into<String>) {
let _ = self.tx.send(msg.into()).await;
}
pub fn try_send(&self, msg: impl Into<String>) {
let _ = self.tx.try_send(msg.into());
}
}
pub trait Agent: Send + Sync + 'static {
fn run(
&self,
nid: String,
ctx: Context,
inputs: Inputs,
log: LogSender,
) -> impl Future<Output = AgentOutput> + Send;
fn shutdown(&self) -> impl Future<Output = ()> + Send {
async {}
}
}