pub struct ToolTask { /* private fields */ }Expand description
Task that invokes a registered tool from the ToolRegistry.
ToolTask executes external tools (magellan, cargo, splice, etc.) with configurable fallback handlers for error recovery.
§Example
ⓘ
use forge_agent::workflow::tasks::ToolTask;
use forge_agent::workflow::tools::ToolInvocation;
use forge_agent::workflow::TaskId;
let task = ToolTask::new(
TaskId::new("tool_task"),
"Magellan Query".to_string(),
"magellan"
)
.args(vec!["find".to_string(), "--name".to_string(), "symbol".to_string()]);Implementations§
Source§impl ToolTask
impl ToolTask
Sourcepub fn new(id: TaskId, name: String, tool_name: impl Into<String>) -> Self
pub fn new(id: TaskId, name: String, tool_name: impl Into<String>) -> Self
Creates a new ToolTask.
§Arguments
id- Task identifiername- Human-readable task nametool_name- Name of the registered tool to invoke
§Example
use forge_agent::workflow::tasks::ToolTask;
use forge_agent::workflow::TaskId;
let task = ToolTask::new(
TaskId::new("tool_task"),
"Query Magellan".to_string(),
"magellan"
);Sourcepub fn args(self, args: Vec<String>) -> Self
pub fn args(self, args: Vec<String>) -> Self
Sets the arguments for the tool invocation.
§Arguments
args- Vector of argument strings
§Returns
Self for builder pattern chaining
§Example
use forge_agent::workflow::tasks::ToolTask;
use forge_agent::workflow::TaskId;
let task = ToolTask::new(
TaskId::new("tool_task"),
"Query Magellan".to_string(),
"magellan"
)
.args(vec!["find".to_string(), "--name".to_string(), "symbol".to_string()]);Sourcepub fn working_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn working_dir(self, dir: impl Into<PathBuf>) -> Self
Sets the working directory for the tool invocation.
§Arguments
dir- Working directory path
§Returns
Self for builder pattern chaining
§Example
use forge_agent::workflow::tasks::ToolTask;
use forge_agent::workflow::TaskId;
let task = ToolTask::new(
TaskId::new("tool_task"),
"Run cargo".to_string(),
"cargo"
)
.working_dir("/home/user/project");Sourcepub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
Adds an environment variable to the tool invocation.
§Arguments
key- Environment variable namevalue- Environment variable value
§Returns
Self for builder pattern chaining
§Example
use forge_agent::workflow::tasks::ToolTask;
use forge_agent::workflow::TaskId;
let task = ToolTask::new(
TaskId::new("tool_task"),
"Run cargo".to_string(),
"cargo"
)
.env("RUST_LOG", "debug");Sourcepub fn with_fallback(self, handler: Box<dyn FallbackHandler>) -> Self
pub fn with_fallback(self, handler: Box<dyn FallbackHandler>) -> Self
Sets the fallback handler for error recovery.
§Arguments
handler- Fallback handler to use on tool failure
§Returns
Self for builder pattern chaining
§Example
use forge_agent::workflow::tasks::ToolTask;
use forge_agent::workflow::tools::RetryFallback;
use forge_agent::workflow::TaskId;
let task = ToolTask::new(
TaskId::new("tool_task"),
"Query Magellan".to_string(),
"magellan"
)
.with_fallback(Box::new(RetryFallback::new(3, 100)));Sourcepub fn invocation(&self) -> &ToolInvocation
pub fn invocation(&self) -> &ToolInvocation
Gets the invocation for this task.
Trait Implementations§
Source§impl WorkflowTask for ToolTask
impl WorkflowTask for ToolTask
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 TaskContext,
) -> Pin<Box<dyn Future<Output = Result<TaskResult, TaskError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 TaskContext,
) -> Pin<Box<dyn Future<Output = Result<TaskResult, TaskError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the task with the provided context. Read more
Source§fn compensation(&self) -> Option<CompensationAction>
fn compensation(&self) -> Option<CompensationAction>
Returns the compensation action for this task (if any). Read more
Auto Trait Implementations§
impl Freeze for ToolTask
impl !RefUnwindSafe for ToolTask
impl Send for ToolTask
impl Sync for ToolTask
impl Unpin for ToolTask
impl UnsafeUnpin for ToolTask
impl !UnwindSafe for ToolTask
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more