ironflow_engine/context/steps/agent.rs
1//! Agent step for [`WorkflowContext`].
2
3use ironflow_store::models::StepKind;
4
5use crate::config::{AgentStepConfig, StepConfig};
6use crate::context::WorkflowContext;
7use crate::error::EngineError;
8use crate::executor::StepOutput;
9
10impl WorkflowContext {
11 /// Execute an agent step.
12 ///
13 /// # Errors
14 ///
15 /// Returns [`EngineError`] if the agent invocation fails or the store errors.
16 ///
17 /// # Examples
18 ///
19 /// ```no_run
20 /// use ironflow_engine::context::WorkflowContext;
21 /// use ironflow_engine::config::AgentStepConfig;
22 /// use ironflow_engine::error::EngineError;
23 ///
24 /// # async fn example(ctx: &mut WorkflowContext) -> Result<(), EngineError> {
25 /// let review = ctx.agent("review", AgentStepConfig::new("Review the code")).await?;
26 /// println!("review: {}", review.output);
27 /// # Ok(())
28 /// # }
29 /// ```
30 pub async fn agent(
31 &mut self,
32 name: &str,
33 config: impl Into<AgentStepConfig>,
34 ) -> Result<StepOutput, EngineError> {
35 self.execute_step(name, StepKind::Agent, StepConfig::Agent(config.into()))
36 .await
37 }
38}