Skip to main content

ShellExecTool

Struct ShellExecTool 

Source
pub struct ShellExecTool { /* private fields */ }
Expand description

A tool that executes shell commands as subprocesses.

ShellExecTool implements the Tool trait and is registered under the name shell.exec. When invoked it spawns the requested executable, waits for it to finish (respecting an optional timeout and turn cancellation), and returns a structured JSON object with stdout, stderr, success, and exit_code fields.

Before execution the tool emits a ShellPermissionRequest so that permission policies (e.g. CommandPolicy) can allow, deny, or require approval for the command.

§Input schema

FieldTypeRequiredDescription
executablestringyesProgram to run.
argv[string]noArguments passed to the executable.
cwdstringnoWorking directory for the subprocess.
env{string:string}noExtra environment variables.
timeout_msintegernoMaximum wall-clock time in milliseconds.

§Example

use agentkit_tool_shell::ShellExecTool;
use agentkit_tools_core::ToolRegistry;

let mut reg = ToolRegistry::new();
reg.register(ShellExecTool::default());

let spec = &reg.specs()[0];
assert_eq!(spec.name.0, "shell.exec");
assert!(spec.annotations.destructive_hint);

Trait Implementations§

Source§

impl Clone for ShellExecTool

Source§

fn clone(&self) -> ShellExecTool

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShellExecTool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShellExecTool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Tool for ShellExecTool

Source§

fn spec(&self) -> &ToolSpec

Returns the ToolSpec describing the shell.exec tool.

Source§

fn proposed_requests( &self, request: &ToolRequest, ) -> Result<Vec<Box<dyn PermissionRequest>>, ToolError>

Extracts a ShellPermissionRequest from the incoming ToolRequest.

The returned request is evaluated by the active PermissionChecker before invoke runs, giving policies such as CommandPolicy a chance to allow or deny the command.

§Errors

Returns ToolError::InvalidInput if the request input cannot be deserialized into the expected schema.

Source§

fn invoke<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: ToolRequest, ctx: &'life1 mut ToolContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Spawns the requested command and returns its output.

The subprocess is spawned with kill_on_drop(true) so it is cleaned up if the future is cancelled. When a timeout_ms is specified in the input the command is aborted after that duration. If a turn cancellation token is present in the ToolContext the command is also aborted when the turn is cancelled.

On success the returned ToolResult contains a JSON object:

{
  "stdout": "...",
  "stderr": "...",
  "success": true,
  "exit_code": 0
}
§Errors
Source§

fn current_spec(&self) -> Option<ToolSpec>

Returns the current specification for this tool, if it should be advertised right now. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.