Skip to main content

AgentPlugin

Trait AgentPlugin 

Source
pub trait AgentPlugin:
    AsyncMessageHandler
    + Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn skills(&self) -> Vec<SkillDefinition>;

    // Provided methods
    fn version(&self) -> &str { ... }
    fn initialize<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), A2AError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn shutdown<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), A2AError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), A2AError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Plugin trait that all agents should implement.

This trait extends AsyncMessageHandler with metadata and capability discovery. Agents implementing this trait can be automatically configured and discovered by the framework.

§Example

use a2a_agents::traits::{AgentPlugin, SkillDefinition};
use a2a_rs::port::AsyncMessageHandler;
use a2a_rs::domain::{A2AError, Message, Task};
use async_trait::async_trait;

#[derive(Clone)]
struct MyAgent;

impl AgentPlugin for MyAgent {
    fn name(&self) -> &str {
        "My Agent"
    }

    fn description(&self) -> &str {
        "A simple example agent"
    }

    fn skills(&self) -> Vec<SkillDefinition> {
        vec![
            SkillDefinition {
                id: "hello".to_string(),
                name: "Say Hello".to_string(),
                description: "Greets the user".to_string(),
                keywords: vec!["hello".into(), "hi".into()],
                examples: vec!["Hello!".into()],
                input_formats: vec!["text".into()],
                output_formats: vec!["text".into()],
            }
        ]
    }
}

#[async_trait]
impl AsyncMessageHandler for MyAgent {
    async fn process_message(
        &self,
        task_id: &str,
        message: &Message,
        session_id: Option<&str>,
    ) -> Result<Task, A2AError> {
        // Implementation
        todo!()
    }

    async fn validate_message(&self, message: &Message) -> Result<(), A2AError> {
        Ok(())
    }
}

Required Methods§

Source

fn name(&self) -> &str

Agent name (displayed to users)

Source

fn description(&self) -> &str

Agent description

Source

fn skills(&self) -> Vec<SkillDefinition>

Skills provided by this agent

Provided Methods§

Source

fn version(&self) -> &str

Version of the agent

Source

fn initialize<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), A2AError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Optional: Initialize the agent (load models, connect to services, etc.)

Source

fn shutdown<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), A2AError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Optional: Cleanup resources

Source

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

Optional: Health check

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§

Source§

impl<T> AgentPlugin for ReimbursementHandler<T>
where T: AsyncTaskManager + Clone + Send + Sync + 'static,

Implement AgentPlugin for ReimbursementHandler with InMemoryTaskStorage