Trait Plugin
pub trait Plugin: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn message_received(
&self,
_message: &mut HookedMessage<'_>,
) -> Result<Verdict, HookError> { ... }
fn run_ending(&self, _end: &HookedEnd<'_>) -> Result<Verdict, HookError> { ... }
fn model_request(
&self,
_request: &mut HookedModelRequest<'_>,
) -> Result<Verdict, HookError> { ... }
fn compaction_before(
&self,
_compaction: &mut HookedCompaction<'_>,
) -> Result<Verdict, HookError> { ... }
fn before_tool(
&self,
_call: &mut HookedCall<'_>,
) -> Result<Verdict, HookError> { ... }
fn after_tool(
&self,
_call: &HookedCall<'_>,
_output: &mut HookedText<'_>,
) -> Result<Verdict, HookError> { ... }
fn subscriptions(&self) -> Subscriptions { ... }
fn events(&self) -> Vec<EventSpec> { ... }
fn observe(&self, _event: &HookEvent) -> Result<(), HookError> { ... }
}Expand description
A compiled hook set around one tool call. Every method has a do-nothing default, so a plugin that cares about one point implements one method.
Required Methods§
Provided Methods§
fn message_received(
&self,
_message: &mut HookedMessage<'_>,
) -> Result<Verdict, HookError>
fn message_received( &self, _message: &mut HookedMessage<'_>, ) -> Result<Verdict, HookError>
A person’s message is about to reach a model: allow it, rewrite its text, or refuse it with
Verdict::Deny and the reason the person reads. Ask and Stop are not verdicts of this
point, and the loop treats them as a hook failure (a refusal).
fn run_ending(&self, _end: &HookedEnd<'_>) -> Result<Verdict, HookError>
fn run_ending(&self, _end: &HookedEnd<'_>) -> Result<Verdict, HookError>
The run would end with an answer: allow it, or return Verdict::Deny with the reason the
model is asked again with. Called once per such end, in the journaled step end:<turn>.
fn model_request(
&self,
_request: &mut HookedModelRequest<'_>,
) -> Result<Verdict, HookError>
fn model_request( &self, _request: &mut HookedModelRequest<'_>, ) -> Result<Verdict, HookError>
A model call is about to be made: rewrite its temperature, its bound on output tokens or its
metadata, or stop the run with Verdict::Stop. Deny and Ask are not verdicts of this
point, and the loop treats them as a hook failure.
fn compaction_before(
&self,
_compaction: &mut HookedCompaction<'_>,
) -> Result<Verdict, HookError>
fn compaction_before( &self, _compaction: &mut HookedCompaction<'_>, ) -> Result<Verdict, HookError>
A history is about to be summarised (ADR 0050, slice H9): add context to the summary request,
or refuse the compaction with Verdict::Deny, and the history is shortened instead.
Stop fails the run; Ask is not a verdict of this point, so it is a failure of class
Invalid and the run fails too (decision 8). A hook never writes the summary itself.
fn before_tool(&self, _call: &mut HookedCall<'_>) -> Result<Verdict, HookError>
fn before_tool(&self, _call: &mut HookedCall<'_>) -> Result<Verdict, HookError>
Before the call runs: rewrite its arguments, refuse it, ask, or stop the run.
fn after_tool(
&self,
_call: &HookedCall<'_>,
_output: &mut HookedText<'_>,
) -> Result<Verdict, HookError>
fn after_tool( &self, _call: &HookedCall<'_>, _output: &mut HookedText<'_>, ) -> Result<Verdict, HookError>
After the tool answered: rewrite what the model will read, or refuse it.
fn subscriptions(&self) -> Subscriptions
fn subscriptions(&self) -> Subscriptions
What the plugin is offered by observe. The default is the core catalogue
(Subscriptions::core), which is what an observer received before custom events existed;
a custom event reaches only a plugin that names it (Subscriptions::core().with("demo.*")).
A pattern whose namespace is neither core nor declared is refused when the agent is built.
fn events(&self) -> Vec<EventSpec>
fn events(&self) -> Vec<EventSpec>
The custom events this plugin declares (ADR 0050, slice H5). The name rules, the core
namespaces and the “declared twice, differently” check are the same as for a tool’s
(EventSpec); a declaration makes the namespace known to every subscription of the agent.
The default declares none.
fn observe(&self, _event: &HookEvent) -> Result<(), HookError>
fn observe(&self, _event: &HookEvent) -> Result<(), HookError>
An event of the catalogue happened (ADR 0050, slice H2). An observer only reads: it runs
outside the journal, its failure is counted and dropped, and it cannot change the run. The
event’s key is stable across replays: a plugin that writes elsewhere dedupes on it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".