Agent

Trait Agent 

Source
pub trait Agent:
    Send
    + Sync
    + 'static {
    // Required method
    fn run(
        &self,
        nid: String,
        ctx: Context,
        inputs: Inputs,
        log: LogSender,
    ) -> impl Future<Output = AgentOutput> + Send;

    // Provided method
    fn shutdown(&self) -> impl Future<Output = ()> + Send { ... }
}
Expand description

Trait for implementing an Actflow agent.

Implement this trait to create your own agent that can be executed by the Actflow workflow engine.

§Example

use actflow_agent_sdk::{Agent, AgentOutput, Context, Inputs, LogSender};

struct MyAgent;

impl Agent for MyAgent {
    async fn run(
        &self,
        nid: String,
        ctx: Context,
        inputs: Inputs,
        log: LogSender,
    ) -> AgentOutput {
        log.send("Processing...").await;
        AgentOutput::success(serde_json::json!({"result": "done"}))
    }
}

Required Methods§

Source

fn run( &self, nid: String, ctx: Context, inputs: Inputs, log: LogSender, ) -> impl Future<Output = AgentOutput> + Send

Execute the agent logic.

§Arguments
  • nid - Node ID in the workflow
  • ctx - Execution context containing process ID, environment variables, and workflow variables
  • inputs - Input data for this agent
  • log - Log sender for streaming log messages
§Returns

Returns an AgentOutput containing the execution status and output data.

Provided Methods§

Source

fn shutdown(&self) -> impl Future<Output = ()> + Send

Called when the agent should shut down.

Override this method to perform cleanup operations. Default implementation does nothing.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§