#[non_exhaustive]pub struct ExecuteToolStage;Expand description
One tool execution (ExecuteToolStage): add telemetry, validate inputs, mock or cache results.
Runs on the tool’s task, inside BeforeToolCallEvent and AfterToolCallEvent.
use serde_json::json;
use strands::middleware::{ExecuteToolResult, ExecuteToolStage, StageStream};
use strands::types::{ToolResultBlock, ToolResultContent};
let mock = ExecuteToolStage::wrap(|context, next| {
if context.tool_use.name != "weather" {
return next.call(context);
}
let result = ToolResultBlock::success(context.tool_use.tool_use_id, vec![ToolResultContent::text("sunny")]);
StageStream::from_result(Ok(ExecuteToolResult::new(result)))
});Implementations§
Source§impl ExecuteToolStage
impl ExecuteToolStage
Sourcepub fn input<F, Fut>(handler: F) -> Middleware<Self>where
F: Fn(<Self as MiddlewareStage>::Context) -> Fut + Send + Sync + 'static,
Fut: Future<Output = StageResult<<Self as MiddlewareStage>::Context>> + Send + 'static,
pub fn input<F, Fut>(handler: F) -> Middleware<Self>where
F: Fn(<Self as MiddlewareStage>::Context) -> Fut + Send + Sync + 'static,
Fut: Future<Output = StageResult<<Self as MiddlewareStage>::Context>> + Send + 'static,
An Input handler (.Input): transforms the context before the stage runs.
Sourcepub fn output<F, Fut>(handler: F) -> Middleware<Self>where
F: Fn(<Self as MiddlewareStage>::Result) -> Fut + Send + Sync + 'static,
Fut: Future<Output = StageResult<<Self as MiddlewareStage>::Result>> + Send + 'static,
pub fn output<F, Fut>(handler: F) -> Middleware<Self>where
F: Fn(<Self as MiddlewareStage>::Result) -> Fut + Send + Sync + 'static,
Fut: Future<Output = StageResult<<Self as MiddlewareStage>::Result>> + Send + 'static,
An Output handler (.Output): transforms the result after the stage runs.
Sourcepub fn wrap<F>(handler: F) -> Middleware<Self>where
F: Fn(<Self as MiddlewareStage>::Context, MiddlewareNext<Self>) -> StageStream<Self> + Send + Sync + 'static,
pub fn wrap<F>(handler: F) -> Middleware<Self>where
F: Fn(<Self as MiddlewareStage>::Context, MiddlewareNext<Self>) -> StageStream<Self> + Send + Sync + 'static,
A Wrap handler (the bare stage or .Wrap): gets the context and next.
Trait Implementations§
Source§impl Clone for ExecuteToolStage
impl Clone for ExecuteToolStage
impl Copy for ExecuteToolStage
Source§impl Debug for ExecuteToolStage
impl Debug for ExecuteToolStage
Source§impl MiddlewareStage for ExecuteToolStage
impl MiddlewareStage for ExecuteToolStage
Auto Trait Implementations§
impl Freeze for ExecuteToolStage
impl RefUnwindSafe for ExecuteToolStage
impl Send for ExecuteToolStage
impl Sync for ExecuteToolStage
impl Unpin for ExecuteToolStage
impl UnsafeUnpin for ExecuteToolStage
impl UnwindSafe for ExecuteToolStage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.