Skip to main content

OutputProcessor

Trait OutputProcessor 

Source
pub trait OutputProcessor: Send + Sync {
    type Context;
    type Output;

    // Required method
    fn process(
        &self,
        output: &Self::Output,
        ctx: &mut Self::Context,
    ) -> impl Future<Output = Result<Signal, EngineError>> + Send;
}
Expand description

Output processor — handles Thinker output and decides flow control.

After a Thinker produces output, each OutputProcessor in the chain processes it and returns Continue or Stop.

§Chain semantics

Processors are consulted in registration order and share a single immutable reference to the thinker’s output (no per-processor clone). The first processor that returns Signal::Stop terminates the loop; subsequent processors in the chain are not invoked for that turn.

Recommended registration order for side-effect + termination processors:

  1. Safety / policy gates (may Stop early)
  2. Side-effect processors (tool execution, message recording)
  3. Loop guards (doom-loop detection)
  4. Round limits (max turns)

§Example

use xz_agent_core::traits::processor::OutputProcessor;
use xz_agent_core::error::EngineError;
use xz_agent_core::types::signal::Signal;

struct StopOnHello;

impl OutputProcessor for StopOnHello {
    type Context = String;
    type Output = String;
    async fn process(&self, output: &Self::Output, ctx: &mut Self::Context) -> Result<Signal, EngineError> {
        if output == "stop" {
            Ok(Signal::Stop)
        } else {
            ctx.push_str(output);
            Ok(Signal::Continue)
        }
    }
}

Required Associated Types§

Source

type Context

The type of context modified during processing.

Source

type Output

The type of output produced by the Thinker.

Required Methods§

Source

fn process( &self, output: &Self::Output, ctx: &mut Self::Context, ) -> impl Future<Output = Result<Signal, EngineError>> + Send

Process the Thinker’s output.

Receives a shared reference so the full processor chain can inspect the same output without requiring Clone.

Returns Continue to proceed or Stop to terminate the engine loop.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<Ctx, Out> OutputProcessor for DynOutputProcessor<Ctx, Out>
where Ctx: Send, Out: Sync,

Source§

type Context = Ctx

Source§

type Output = Out