Skip to main content

before_model

Attribute Macro before_model 

Source
#[before_model]
Expand description

Middleware: run a hook before each model call.

The decorated async function must accept &mut ModelRequest and return Result<(), SynapticError>.

§Example

use synaptic_macros::before_model;
use synaptic_middleware::ModelRequest;
use synaptic_core::SynapticError;

#[before_model]
async fn add_context(request: &mut ModelRequest) -> Result<(), SynapticError> {
    request.system_prompt = Some("Be helpful".into());
    Ok(())
}

let mw = add_context(); // Arc<dyn AgentMiddleware>