Skip to main content

wrap_tool_call

Attribute Macro wrap_tool_call 

Source
#[wrap_tool_call]
Expand description

Middleware: wrap a tool call with custom logic.

The decorated async function must accept ToolCallRequest and &dyn ToolCaller, returning Result<Value, SynapticError>.

§Example

use synaptic_macros::wrap_tool_call;
use synaptic_middleware::{ToolCallRequest, ToolCaller};
use synaptic_core::SynapticError;
use serde_json::Value;

#[wrap_tool_call]
async fn log_tool(request: ToolCallRequest, next: &dyn ToolCaller) -> Result<Value, SynapticError> {
    println!("Calling tool: {}", request.call.name);
    next.call(request).await
}

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