Skip to main content

Agent

Trait Agent 

Source
pub trait Agent: Send + Sync {
    // Required method
    fn run(
        &self,
        config: AgentConfig<'_>,
        tx: Sender<AgentMessage>,
    ) -> impl Future<Output = Result<(), RunError>> + Send;
}
Expand description

Trait for an agent under evaluation.

Implementors are responsible for:

  • Creating their own MCP connections (if needed)
  • Running the agent with the provided configuration
  • Sending AgentMessages to the provided channel
  • Sending AgentMessage::Done when the agent finishes

§Example

struct MyAgent;

impl Agent for MyAgent {
    async fn run(&self, config: AgentConfig<'_>, tx: Sender<AgentMessage>) -> Result<(), RunError> {
        tx.send(AgentMessage::text("msg_1", "Hello", true, "test")).await
            .map_err(|e| RunError::ChannelSendFailed(e.to_string()))?;
        tx.send(AgentMessage::Done).await
            .map_err(|e| RunError::ChannelSendFailed(e.to_string()))?;
        Ok(())
    }
}

Required Methods§

Source

fn run( &self, config: AgentConfig<'_>, tx: Sender<AgentMessage>, ) -> impl Future<Output = Result<(), RunError>> + Send

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§