Skip to main content

rs_adk/text/
sequential.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4
5use super::TextAgent;
6use crate::error::AgentError;
7use crate::state::State;
8
9/// Runs text agents sequentially. Each agent sees state mutations from
10/// previous agents. The final agent's output is the pipeline's output.
11pub struct SequentialTextAgent {
12    name: String,
13    children: Vec<Arc<dyn TextAgent>>,
14}
15
16impl SequentialTextAgent {
17    /// Create a new sequential agent that runs children in order.
18    pub fn new(name: impl Into<String>, children: Vec<Arc<dyn TextAgent>>) -> Self {
19        Self {
20            name: name.into(),
21            children,
22        }
23    }
24}
25
26#[async_trait]
27impl TextAgent for SequentialTextAgent {
28    fn name(&self) -> &str {
29        &self.name
30    }
31
32    async fn run(&self, state: &State) -> Result<String, AgentError> {
33        let mut last_output = String::new();
34        for child in &self.children {
35            last_output = child.run(state).await?;
36            // Feed output as input for the next agent.
37            state.set("input", &last_output);
38        }
39        Ok(last_output)
40    }
41}