#[non_exhaustive]pub enum InterventionAction<E> {
Proceed(Proceed),
Deny(Deny),
Guide(Guide),
Confirm(Confirm),
Transform(Transform<E>),
}Expand description
What a handler decides at a lifecycle point (InterventionAction), for the event E it was
given.
| Action | before_invocation | before_tool_call | before_model_call | after_tool_call | after_model_call |
|---|---|---|---|---|---|
Proceed | - | - | - | - | - |
Deny | cancel | cancel | cancel | no effect | no effect |
Guide | cancel | cancel | inject | no effect | inject and retry |
Confirm | no effect | confirm | no effect | no effect | no effect |
Transform | apply | apply | apply | apply | apply |
A cancel by Deny (or a rejected Confirm) skips the remaining handlers; an action with no
effect logs a warning.
use strands::hooks::BeforeToolCallEvent;
use strands::interventions::InterventionAction;
let deny = InterventionAction::<BeforeToolCallEvent>::deny("not authorized");
assert_eq!(deny.action_type(), "deny");
let redact = InterventionAction::transform(|event: &mut BeforeToolCallEvent| {
event.tool_use_mut().input = serde_json::json!({});
});
assert_eq!(redact.action_type(), "transform");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Proceed(Proceed)
Continue unchanged.
Deny(Deny)
Block the operation.
Guide(Guide)
Steer the model with feedback.
Confirm(Confirm)
Ask a human first.
Transform(Transform<E>)
Mutate the event.
Implementations§
Source§impl<E> InterventionAction<E>
impl<E> InterventionAction<E>
Sourcepub fn deny(reason: impl Into<String>) -> Self
pub fn deny(reason: impl Into<String>) -> Self
Block the operation (deny); the reason is shown to the model.
Sourcepub fn guide(feedback: impl Into<String>) -> Self
pub fn guide(feedback: impl Into<String>) -> Self
Steer the model (guide); the feedback is shown to the model.
Sourcepub fn confirm(prompt: impl Into<String>) -> Self
pub fn confirm(prompt: impl Into<String>) -> Self
Ask a human (confirm), with the default approval test and no pre-collected answer. Build
a Confirm for the options.
Sourcepub fn transform<R: HookOutput>(
apply: impl FnOnce(&mut E) -> R + Send + 'static,
) -> Self
pub fn transform<R: HookOutput>( apply: impl FnOnce(&mut E) -> R + Send + 'static, ) -> Self
Mutate the event (transform), with a closure returning () or a Result.
Sourcepub fn action_type(&self) -> &'static str
pub fn action_type(&self) -> &'static str
The action’s type tag: proceed, deny, guide, confirm or transform.
Trait Implementations§
Source§impl<E> Debug for InterventionAction<E>
impl<E> Debug for InterventionAction<E>
Source§impl<E> From<Confirm> for InterventionAction<E>
impl<E> From<Confirm> for InterventionAction<E>
Source§impl<E> From<Deny> for InterventionAction<E>
impl<E> From<Deny> for InterventionAction<E>
Source§impl<E> From<Guide> for InterventionAction<E>
impl<E> From<Guide> for InterventionAction<E>
Source§impl<E> From<Proceed> for InterventionAction<E>
impl<E> From<Proceed> for InterventionAction<E>
Auto Trait Implementations§
impl<E> !RefUnwindSafe for InterventionAction<E>
impl<E> !Sync for InterventionAction<E>
impl<E> !UnwindSafe for InterventionAction<E>
impl<E> Freeze for InterventionAction<E>
impl<E> Send for InterventionAction<E>
impl<E> Unpin for InterventionAction<E>
impl<E> UnsafeUnpin for InterventionAction<E>
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
§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.