swiftide_agents/
task_agent.rs1use std::sync::Arc;
2
3use async_trait::async_trait;
4use swiftide_core::prompt::Prompt;
5use swiftide_tasks::{NodeId, TaskNode};
6use tokio::sync::Mutex;
7
8use crate::{Agent, errors::AgentError};
9
10#[derive(Clone, Debug)]
17pub struct TaskAgent(Arc<Mutex<Agent>>);
18
19impl From<Agent> for TaskAgent {
20 fn from(agent: Agent) -> Self {
21 Self(Arc::new(Mutex::new(agent)))
22 }
23}
24
25#[async_trait]
26impl TaskNode for TaskAgent {
27 type Input = Prompt;
28 type Output = ();
29 type Error = AgentError;
30
31 async fn evaluate(
32 &self,
33 _node_id: &NodeId<
34 dyn TaskNode<Input = Self::Input, Output = Self::Output, Error = Self::Error>,
35 >,
36 input: &Self::Input,
37 ) -> Result<Self::Output, Self::Error> {
38 self.0.lock().await.query(input.clone()).await
39 }
40}