Skip to main content

Reducer

Trait Reducer 

Source
pub trait Reducer: Send + Sync {
    // Required methods
    fn reduce<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        current: Option<&'life1 Value>,
        update: &'life2 Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn name(&self) -> &str;
    fn reducer_type(&self) -> ReducerType;
}
Expand description

Reducer trait for state update strategies

A Reducer defines how to merge a state update with an existing value. Different keys in the state can have different reducers.

§Example

// Messages should be appended
graph.add_reducer("messages", Box::new(AppendReducer));

// Result should overwrite
graph.add_reducer("result", Box::new(OverwriteReducer));

Required Methods§

Source

fn reduce<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, current: Option<&'life1 Value>, update: &'life2 Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Reduce the current value with the update value

§Arguments
  • current - The current value (None if key doesn’t exist)
  • update - The new value to merge
§Returns

The merged result

Source

fn name(&self) -> &str

Returns the name of this reducer

Source

fn reducer_type(&self) -> ReducerType

Returns the type of this reducer

Implementors§