BaseAgent

Trait BaseAgent 

Source
pub trait BaseAgent: Send + Sync {
    // Required method
    fn receive_event(&self, event: Box<dyn Event>) -> Vec<Box<dyn Event>>;
}
Expand description

Base trait for synchronous agents in the system.

Agents process events and optionally emit new events. This trait defines the simplest agent interface for synchronous event processing.

§When to Use

Use BaseAgent when:

  • Event processing doesn’t require I/O operations
  • Processing is fast and won’t block
  • You have a simple transformation pipeline

Use BaseAsyncAgent when:

  • You need to call LLMs or external APIs
  • Processing involves database queries
  • Operations may take significant time

§Examples

use mojentic::agents::BaseAgent;
use mojentic::event::Event;

struct TransformAgent;

impl BaseAgent for TransformAgent {
    fn receive_event(&self, event: Box<dyn Event>) -> Vec<Box<dyn Event>> {
        // Process the event synchronously and return new events
        vec![]
    }
}

Required Methods§

Source

fn receive_event(&self, event: Box<dyn Event>) -> Vec<Box<dyn Event>>

Process an event synchronously and return resulting events.

This method is called when an event is routed to this agent. The agent can process the event and return zero or more new events to be processed.

§Arguments
  • event - The event to process
§Returns

A vector of new events to be dispatched (can be empty).

Implementors§