Skip to main content

potato_agent/agents/
runner.rs

1use crate::agents::{
2    error::AgentError, run_context::ResumeContext, session::SessionState, types::AgentResponse,
3};
4use async_trait::async_trait;
5use std::fmt::Debug;
6
7/// Final result of a completed agent run.
8#[derive(Debug, Clone)]
9pub struct AgentRunResult {
10    pub final_response: AgentResponse,
11    pub iterations: u32,
12    pub completion_reason: String,
13    /// Combined text from all parallel agents (set by `CollectAll` merge strategy).
14    pub combined_text: Option<String>,
15}
16
17/// Outcome of calling `AgentRunner::run()`.
18#[derive(Debug)]
19pub enum AgentRunOutcome {
20    /// The run completed — final answer available.
21    Complete(Box<AgentRunResult>),
22    /// The agent is paused and needs user input before continuing.
23    NeedsInput {
24        question: String,
25        resume_context: ResumeContext,
26    },
27}
28
29impl AgentRunOutcome {
30    pub fn complete(result: AgentRunResult) -> Self {
31        Self::Complete(Box::new(result))
32    }
33}
34
35/// Core trait implemented by all runnable agents (Agent, SequentialAgent, ParallelAgent, AgentTool).
36#[async_trait]
37pub trait AgentRunner: Send + Sync + Debug {
38    fn id(&self) -> &str;
39
40    async fn run(
41        &self,
42        input: &str,
43        session: &mut SessionState,
44    ) -> Result<AgentRunOutcome, AgentError>;
45
46    /// Resume a previously paused run with the user's answer.
47    async fn resume(
48        &self,
49        user_answer: &str,
50        ctx: ResumeContext,
51        session: &mut SessionState,
52    ) -> Result<AgentRunOutcome, AgentError>;
53}