pub struct PluginToolAdapter { /* private fields */ }Expand description
An AgentTool backed by a plugin’s 4-function handle. One adapter is built
per registered tool (schema copied from the registration) and inserted into
the session’s tool set in B2.
Holds a clone of the session’s PluginKeepalive so the cdylib that owns
handle’s fn pointers stays mapped for as long as the adapter (and thus any
in-flight execute) may call them. Without this the Library could drop
(unload the cdylib) while a fn pointer is still callable → UAF. The keepalive
is Arc-shared with every other adapter built from the same session, so the
last drop — which can only happen once the harness’s tool vec drops — unloads.
Implementations§
Source§impl PluginToolAdapter
impl PluginToolAdapter
Sourcepub fn new(
schema: Tool,
handle: PluginToolHandle,
keepalive: Arc<PluginKeepalive>,
) -> Self
pub fn new( schema: Tool, handle: PluginToolHandle, keepalive: Arc<PluginKeepalive>, ) -> Self
Build an adapter from the registered schema + handle + the session’s
keepalive. label defaults to the tool name. The keepalive clone keeps
the owning cdylib mapped for the adapter’s lifetime.
Sourcepub fn with_context(self, context: ToolCallContext) -> Self
pub fn with_context(self, context: ToolCallContext) -> Self
Attach the session’s context, so each call carries cwd + sessionId.
Builder-style so the three-argument PluginToolAdapter::new keeps
working for callers that have no session (tests, the SDK smoke test).
Trait Implementations§
Source§impl AgentTool for PluginToolAdapter
impl AgentTool for PluginToolAdapter
Source§fn schema(&self) -> &Tool
fn schema(&self) -> &Tool
Source§fn execution_mode(&self) -> ToolExecutionMode
fn execution_mode(&self) -> ToolExecutionMode
Sequential forces one-at-a-time for
the whole batch when any tool in it returns Sequential; Parallel
(default) allows concurrency.Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
tool_call_id: &'life1 str,
params: Value,
signal: CancellationToken,
on_update: Arc<dyn Fn(ToolResultPartial) + Send + Sync>,
) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
tool_call_id: &'life1 str,
params: Value,
signal: CancellationToken,
on_update: Arc<dyn Fn(ToolResultPartial) + Send + Sync>,
) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, AgentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Err(AgentError) on failure — the loop
encodes the error message into an error ToolResultMessage. Read moreSource§fn prepare_arguments(&self, args: Value) -> Result<Value, AgentError>
fn prepare_arguments(&self, args: Value) -> Result<Value, AgentError>
prepareArguments.