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
impl BashTool
Sourcepub fn new(workspace: Workspace) -> Self
pub fn new(workspace: Workspace) -> Self
Create a bash tool bound to workspace, running commands with HostLauncher.
Sourcepub fn with_launcher(self, launcher: Arc<dyn CommandLauncher>) -> Self
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));Sourcepub fn with_output_store(self, store: Arc<dyn OutputStore>) -> Self
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));Sourcepub async fn spawn(
&self,
ctx: Arc<dyn ToolContext>,
command: &str,
) -> Result<RunningCommand>
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
impl Tool for BashTool
Source§fn egress(&self, _args: &Value) -> ToolEgress
fn egress(&self, _args: &Value) -> ToolEgress
What the launcher’s commands reach on the network (CommandLauncher::egress).
Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§fn parameters_schema(&self) -> Option<Value>
fn parameters_schema(&self) -> Option<Value>
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,
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,
Source§fn declaration(&self) -> Value
fn declaration(&self) -> Value
Source§fn enhanced_description(&self) -> String
fn enhanced_description(&self) -> String
Source§fn is_long_running(&self) -> bool
fn is_long_running(&self) -> bool
Source§fn is_builtin(&self) -> bool
fn is_builtin(&self) -> bool
google_search, url_context). Read more