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§
Sourcefn run(
&self,
nid: String,
ctx: Context,
inputs: Inputs,
log: LogSender,
) -> impl Future<Output = AgentOutput> + Send
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 workflowctx- Execution context containing process ID, environment variables, and workflow variablesinputs- Input data for this agentlog- Log sender for streaming log messages
§Returns
Returns an AgentOutput containing the execution status and output data.
Provided Methods§
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.