autoagents_core/agent/
executor.rs

1use super::runnable::AgentState;
2use crate::session::Task;
3use async_trait::async_trait;
4use autoagents_llm::chat::ChatMessage;
5use autoagents_llm::LLMProvider;
6use serde::de::DeserializeOwned;
7use serde::Serialize;
8use std::error::Error;
9use std::fmt::Debug;
10use std::sync::Arc;
11use tokio::sync::Mutex;
12
13/// Result of processing a single turn
14#[derive(Debug)]
15pub enum TurnResult<T> {
16    /// Continue processing
17    Continue,
18    /// Final result obtained
19    Complete(T),
20    /// Error occurred but can continue
21    Error(String),
22}
23
24/// Base trait for agent execution strategies
25#[async_trait]
26pub trait AgentExecutor: Send + Sync + 'static {
27    type Output: Serialize + DeserializeOwned + Send + Sync;
28    type Error: Error + Send + Sync + 'static;
29
30    /// Execute the agent with the given session
31    async fn execute(
32        &self,
33        llm: Arc<dyn LLMProvider>,
34        task: Task,
35        state: Arc<Mutex<AgentState>>,
36    ) -> Result<Self::Output, Self::Error>;
37
38    /// Process a single turn of conversation
39    async fn process_turn(
40        &self,
41        llm: Arc<dyn LLMProvider>,
42        messages: &mut Vec<ChatMessage>,
43        state: Arc<Mutex<AgentState>>,
44    ) -> Result<TurnResult<Self::Output>, Self::Error>;
45
46    /// Get the maximum number of turns allowed
47    fn max_turns(&self) -> usize {
48        10
49    }
50}