pub enum ToolResult {
Success {
tool_call_id: String,
output: String,
sources: Vec<Source>,
diffs: Vec<FileDiff>,
working_dir: Option<PathBuf>,
},
Failure {
tool_call_id: String,
output: String,
},
Interrupt {
tool_call_id: String,
payload: Arc<dyn InterruptPayload>,
},
}Expand description
Result of a tool execution, returned by Tool::execute and fed back to
the LLM as a "role": "tool" message.
Three variants cover the full lifecycle of a tool call:
Success— The tool ran without error. Theoutputfield contains the text payload sent back to the model. Optionalsources(URLs the agent can cite) anddiffs(unified diffs for file-mutating tools) may be attached.Failure— The tool encountered an error (invalid arguments, I/O failure, etc.). Theoutputfield carries a human- and LLM-readable error description. UnlikeSuccess, no sources or diffs are included.Interrupt— The tool needs user interaction before continuing (e.g. plan approval, choice picker). The agent loop should halt and surface theoutput(structured as JSON) to the caller for handling.
§Construction helpers
Prefer the associated constructors on the impl block rather than building
variants directly:
use flashmind_types::tool::ToolResult;
// Basic success
ToolResult::success(call_id, "file written")
// Failure with error message
ToolResult::failure(call_id, "permission denied")
// Success with file diffs attached
ToolResult::success_with_diffs(call_id, "replaced", vec![diff])
// Interrupt for interactive prompt
ToolResult::interrupt(call_id, Arc::new(MyPayload { ... }))
// Chain .with_sources() onto any Success
ToolResult::success(call_id, results).with_sources(srcs)§Relation to message::ToolResult
This type lives in the tool module and represents the raw outcome of
executing a tool. It is converted into a Message
with role: "tool" (via AgentEvent::ToolResult)
before being appended to the conversation history sent to the LLM.
Variants§
Success
Tool executed successfully.
Fields
Failure
Tool execution failed.
Interrupt
The agent loop should stop and return this result to the caller for interactive handling. The typed payload is downcast by the caller to determine the interrupt kind.
Implementations§
Source§impl ToolResult
impl ToolResult
Sourcepub fn success(tool_call_id: &str, output: impl Into<String>) -> Self
pub fn success(tool_call_id: &str, output: impl Into<String>) -> Self
Create a basic success result with no sources or diffs.
Sourcepub fn failure(tool_call_id: &str, output: impl Into<String>) -> Self
pub fn failure(tool_call_id: &str, output: impl Into<String>) -> Self
Create a failure result with an error message.
Sourcepub fn success_with_diffs(
tool_call_id: &str,
output: impl Into<String>,
diffs: Vec<FileDiff>,
) -> Self
pub fn success_with_diffs( tool_call_id: &str, output: impl Into<String>, diffs: Vec<FileDiff>, ) -> Self
Create a success result that includes file diffs for tools that mutate content (file write, text replace, etc.).
Sourcepub fn interrupt(tool_call_id: &str, payload: Arc<dyn InterruptPayload>) -> Self
pub fn interrupt(tool_call_id: &str, payload: Arc<dyn InterruptPayload>) -> Self
Create an interrupt result that pauses the agent loop for interactive user handling (command approval, OAuth, etc.).
NOTE: the agent turn ends without a tool result in the conversation,
leaving a dangling tool call. Callers must add a ConversationEntry::tool
with the same tool_call_id after handling the interrupt.
Sourcepub fn with_sources(self, sources: Vec<Source>) -> Self
pub fn with_sources(self, sources: Vec<Source>) -> Self
Attach source URLs to a Success result. Returns self unchanged if
the variant is not Success.
This is designed for method chaining:
ToolResult::success(id, "results").with_sources(srcs)Sourcepub fn with_working_dir(self, path: PathBuf) -> Self
pub fn with_working_dir(self, path: PathBuf) -> Self
Change this agent’s working directory after the call succeeds.
Tools returning this effect must set concurrent() to false.
Sourcepub fn working_dir(&self) -> Option<&Path>
pub fn working_dir(&self) -> Option<&Path>
Working directory selected by a successful tool call.
Sourcepub fn tool_call_id(&self) -> &str
pub fn tool_call_id(&self) -> &str
Return the tool call ID echoed from the original invocation.
Sourcepub fn output(&self) -> String
pub fn output(&self) -> String
Return the text output payload (success result, error message, or interrupt display string).
Sourcepub fn payload(&self) -> Option<&Arc<dyn InterruptPayload>>
pub fn payload(&self) -> Option<&Arc<dyn InterruptPayload>>
Return the typed interrupt payload, if this is an Interrupt variant.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check whether this result represents a successful execution.
Sourcepub fn is_interrupt(&self) -> bool
pub fn is_interrupt(&self) -> bool
Check whether this result is an interrupt requiring user interaction.
Sourcepub fn sources(&self) -> &[Source]
pub fn sources(&self) -> &[Source]
Return the attached source references, or an empty slice for non-success variants.
Sourcepub fn diffs(&self) -> &[FileDiff]
pub fn diffs(&self) -> &[FileDiff]
Return the attached file diffs, or an empty slice for non-success variants.
Sourcepub fn truncate_output(&mut self, max_bytes: usize, max_lines: usize)
pub fn truncate_output(&mut self, max_bytes: usize, max_lines: usize)
Truncate output to fit within byte and line limits.
Appends \n[truncated] when the output was cut.