Skip to main content

rs_adk/text/
tap.rs

1use async_trait::async_trait;
2
3use super::TextAgent;
4use crate::error::AgentError;
5use crate::state::State;
6
7/// Read-only observation agent. Calls a function with the state but
8/// cannot mutate it. Returns empty string. No LLM call.
9pub struct TapTextAgent {
10    name: String,
11    func: Box<dyn Fn(&State) + Send + Sync>,
12}
13
14impl TapTextAgent {
15    /// Create a new tap agent for read-only observation.
16    pub fn new(name: impl Into<String>, f: impl Fn(&State) + Send + Sync + 'static) -> Self {
17        Self {
18            name: name.into(),
19            func: Box::new(f),
20        }
21    }
22}
23
24#[async_trait]
25impl TextAgent for TapTextAgent {
26    fn name(&self) -> &str {
27        &self.name
28    }
29
30    async fn run(&self, state: &State) -> Result<String, AgentError> {
31        (self.func)(state);
32        Ok(String::new())
33    }
34}