Skip to main content

BashTool

Struct BashTool 

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

Runs a shell command in the workspace root with a timeout.

Streams stdout and stderr line-by-line via ToolContext::emit_progress so UI layers can display live terminal output. The result carries at most INLINE_OUTPUT_CHARS of output, stdout and stderr together: a longer stream keeps its first third and last two thirds of its share around a marker naming the bytes left out (spec 3.1 §7.33 fix 8). With an OutputStore (with_output_store) the whole output, up to Workspace::max_output bytes, goes to a file the marker and the result’s output_id name. Memory stays bounded either way.

The command reads end of file from standard input and starts in a new session, so it has no controlling terminal and leads its own process group. When the shell exits, the rest of the group — anything it started in the background — is killed, unless Workspace::bash_kill_group_on_exit turns that off. A timeout or a cancelled call (dropping its future) kills the whole group too. A process that starts its own session or group escapes the kill.

On Windows the command starts suspended and runs only once it is in a Job Object, so every process it starts belongs to the job and none can leave it. The job’s processes are killed where Unix kills the group, and when the agent process exits during the call (spec 3.2 §10 W1).

The process comes from a CommandLauncher: HostLauncher by default, another one through with_launcher.

Implementations§

Source§

impl BashTool

Source

pub fn new(workspace: Workspace) -> Self

Create a bash tool bound to workspace, running commands with HostLauncher.

Source

pub fn with_launcher(self, launcher: Arc<dyn CommandLauncher>) -> Self

Build each command with launcher instead of HostLauncher.

The timeout ceiling, output cap, streaming, standard input, session and process-group kill stay with the tool. Implements spec 3.1 §10 D1.

§Example
use std::sync::Arc;

use adk_devtools::{BashTool, HostLauncher, Workspace};

let workspace = Workspace::new("./my-repo").allow_bash(true);
let bash = BashTool::new(workspace).with_launcher(Arc::new(HostLauncher));
Source

pub fn with_output_store(self, store: Arc<dyn OutputStore>) -> Self

Keep the whole output of a command whose result is cut in a file from store, named by the result’s output_id (spec 3.1 §7.33 fix 8). The file holds at most Workspace::max_output bytes.

§Example
use std::sync::Arc;

use adk_core::ToolContext;
use adk_devtools::{BashTool, OutputFile, OutputStore, Workspace};

struct Temp;

impl OutputStore for Temp {
    fn create(&self, ctx: &dyn ToolContext, _command: &str) -> std::io::Result<OutputFile> {
        let id = ctx.function_call_id().to_string();
        let path = std::env::temp_dir().join(format!("{id}.log"));
        let file = std::fs::File::create(&path)?;
        Ok(OutputFile { id, path, file })
    }
}

let bash = BashTool::new(Workspace::new(".").allow_bash(true))
    .with_output_store(Arc::new(Temp));
Source

pub async fn spawn( &self, ctx: Arc<dyn ToolContext>, command: &str, ) -> Result<RunningCommand>

Starts command and returns at once (spec 3.1 §10 D10).

The command runs as execute runs it — the same launcher, environment, standard input, session and process group — with no timeout: the caller decides when to kill it. Its output streams through ctx while ctx listens and is kept as execute keeps it; RunningCommand::keep_output sends all of it to a file. Dropping the RunningCommand kills the command’s processes.

§Errors

Returns BashDisabled when the workspace does not allow bash, or the error that kept the command from starting.

§Example
ⓘ
let mut running = bash.spawn(ctx, "cargo build").await?;
let exit_code = running.wait().await?;
let result = running.result(exit_code);

Trait Implementations§

Source§

impl Tool for BashTool

Source§

fn egress(&self, _args: &Value) -> ToolEgress

What the launcher’s commands reach on the network (CommandLauncher::egress).

Source§

fn name(&self) -> &str

Returns the unique name of this tool.
Source§

fn description(&self) -> &str

Returns a human-readable description of what this tool does.
Source§

fn parameters_schema(&self) -> Option<Value>

Returns the JSON Schema for this tool’s parameters, if any.
Source§

fn execute<'life0, 'async_trait>( &'life0 self, ctx: Arc<dyn ToolContext>, args: Value, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executes the tool with the given context and arguments.
Source§

fn declaration(&self) -> Value

Returns the tool declaration that should be exposed to model providers. Read more
Source§

fn enhanced_description(&self) -> String

Returns an enhanced description that may include additional notes. For long-running tools, this includes a warning not to call the tool again if it has already returned a pending status. Default implementation returns the base description.
Source§

fn is_long_running(&self) -> bool

Indicates whether the tool is a long-running operation. Long-running tools typically return a task ID immediately and complete the operation asynchronously.
Source§

fn is_builtin(&self) -> bool

Indicates whether this tool is a built-in server-side tool (e.g., google_search, url_context). Read more
Source§

fn response_schema(&self) -> Option<Value>

Returns the JSON Schema for this tool’s response, if any.
Source§

fn annotations(&self) -> Option<&Value>

Returns the behaviour annotations the tool’s publisher declared, if any. Read more
Source§

fn origin(&self) -> &str

Returns who publishes this tool: the toolset or server it comes from. Read more
Source§

fn required_scopes(&self) -> &[&str]

Returns the scopes required to execute this tool. Read more
Source§

fn is_read_only(&self) -> bool

Indicates whether this tool performs no side effects. Read more
Source§

fn effect(&self) -> ToolEffect

Returns the side-effect class of this tool. Read more
Source§

fn timeout_override(&self) -> Option<Option<Duration>>

Overrides the per-call timeout the agent applies to this tool. Read more
Source§

fn is_concurrency_safe(&self) -> bool

Indicates whether this tool is safe for concurrent execution. Read more
Source§

fn batch_group(&self) -> Option<BatchGroup>

The ordered batch this tool’s calls belong to, if any. Read more
Source§

fn is_agent_delegation(&self) -> bool

Indicates whether this tool delegates work to another agent. Read more
Source§

fn approval_evidence(&self, _args: &Value) -> Vec<Evidence>

What an approver sees with a call with args when it is held, such as the exact image it would send (Evidence). Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for BashTool

§

impl !UnwindSafe for BashTool

§

impl Forget for BashTool

§

impl Freeze for BashTool
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn ReadLedger> is !null: Freeze, PhantomData<ArcInner<dyn ReadLedger>>: Freeze, *const ArcInner<Mutex<HashMap<String, String>>> is !null: Freeze, PhantomData<ArcInner<Mutex<HashMap<String, String>>>>: Freeze, PhantomData<String>: Freeze, PhantomData<Pattern>: Freeze, *const ArcInner<dyn CommandLauncher> is !null: Freeze, PhantomData<ArcInner<dyn CommandLauncher>>: Freeze, *const ArcInner<dyn OutputStore> is !null: Freeze, PhantomData<ArcInner<dyn OutputStore>>: Freeze,

§

impl Move for BashTool

§

impl Send for BashTool
where RawVecInner: Send, Arc<dyn ReadLedger>: Send, Arc<Mutex<HashMap<String, String>>>: Send, Arc<dyn CommandLauncher>: Send, Arc<dyn OutputStore>: Send,

§

impl Sync for BashTool
where RawVecInner: Sync, Arc<dyn ReadLedger>: Sync, Arc<Mutex<HashMap<String, String>>>: Sync, Arc<dyn CommandLauncher>: Sync, Arc<dyn OutputStore>: Sync,

§

impl Unpin for BashTool

§

impl UnsafeUnpin for BashTool

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more