gemini_adk_rs/text/
fn_agent.rs1use async_trait::async_trait;
2
3use super::TextAgent;
4use crate::error::AgentError;
5use crate::state::State;
6
7type StateFn = Box<dyn Fn(&State) -> Result<String, AgentError> + Send + Sync>;
9
10pub struct FnTextAgent {
12 name: String,
13 func: StateFn,
14}
15
16impl FnTextAgent {
17 pub fn new(
19 name: impl Into<String>,
20 f: impl Fn(&State) -> Result<String, AgentError> + Send + Sync + 'static,
21 ) -> Self {
22 Self {
23 name: name.into(),
24 func: Box::new(f),
25 }
26 }
27}
28
29#[async_trait]
30impl TextAgent for FnTextAgent {
31 fn name(&self) -> &str {
32 &self.name
33 }
34
35 async fn run(&self, state: &State) -> Result<String, AgentError> {
36 (self.func)(state)
37 }
38}