Agent

Trait Agent 

Source
pub trait Agent: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn supports(&self, task_type: TaskType) -> bool;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        input: AgentInput,
    ) -> Pin<Box<dyn Future<Output = Result<AgentOutput>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn config_schema(&self) -> ConfigSchema { ... }
    fn metrics(&self) -> AgentMetrics { ... }
}
Expand description

Trait that all agents must implement

The Agent trait defines the interface for specialized agents that perform different tasks within the RiceCoder framework. All agents must implement this trait to be registered and executed by the orchestrator.

§Examples

use ricecoder_agents::{Agent, AgentInput, AgentOutput};
use async_trait::async_trait;

struct MyAgent;

#[async_trait]
impl Agent for MyAgent {
    fn id(&self) -> &str {
        "my-agent"
    }

    fn name(&self) -> &str {
        "My Agent"
    }

    fn description(&self) -> &str {
        "A custom agent for specific tasks"
    }

    fn supports(&self, task_type: TaskType) -> bool {
        matches!(task_type, TaskType::CodeReview)
    }

    async fn execute(&self, input: AgentInput) -> Result<AgentOutput> {
        // Implement agent logic here
        Ok(AgentOutput::default())
    }
}

Required Methods§

Source

fn id(&self) -> &str

Get the agent’s unique identifier

The ID should be a stable, unique identifier for this agent that can be used to look up the agent in the registry.

§Returns

A string slice containing the agent’s unique identifier

Source

fn name(&self) -> &str

Get the agent’s human-readable name

The name is used for display purposes and should be descriptive but concise.

§Returns

A string slice containing the agent’s human-readable name

Source

fn description(&self) -> &str

Get the agent’s description

The description provides more detailed information about what the agent does and can be used for help text or documentation.

§Returns

A string slice containing the agent’s description

Source

fn supports(&self, task_type: TaskType) -> bool

Check if the agent supports a specific task type

This method is used by the registry to determine which agents can handle specific task types. An agent can support multiple task types.

§Arguments
  • task_type - The task type to check support for
§Returns

true if the agent supports the given task type, false otherwise

Source

fn execute<'life0, 'async_trait>( &'life0 self, input: AgentInput, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the agent with the given input

This is the main method that performs the agent’s work. It should be async to support non-blocking I/O and streaming responses.

§Arguments
  • input - The input containing the task, context, and configuration
§Returns

A Result containing the agent’s output or an error

§Errors

Returns an error if the agent execution fails for any reason

Provided Methods§

Source

fn config_schema(&self) -> ConfigSchema

Get the agent’s configuration schema

This method returns a JSON schema describing the configuration options that the agent accepts. This is used for validation and documentation.

§Returns

A ConfigSchema describing the agent’s configuration options

Source

fn metrics(&self) -> AgentMetrics

Get the agent’s performance metrics

This method returns metrics about the agent’s performance, including execution counts, success rates, and average execution time.

§Returns

An AgentMetrics struct containing performance metrics

Implementors§