pub struct ToolResult {
pub output: Value,
pub hash: Hash,
pub execution_time: Duration,
pub tokens_used: Option<u32>,
pub timestamp: String,
pub tool_name: String,
}Expand description
Result of a tool execution with cryptographic verification data.
§Example
use vex_llm::ToolResult;
use serde_json::json;
use std::time::Duration;
let result = ToolResult::new(
"calculator",
&json!({"expression": "2+2"}),
json!({"result": 4}),
Duration::from_millis(5),
);
// Hash is automatically computed
assert!(!result.hash.to_string().is_empty());
assert_eq!(result.output["result"], 4);Fields§
§output: ValueThe output value from the tool
hash: HashSHA-256 hash of (tool_name + args + output + timestamp) Used for Merkle tree integration and verification
execution_time: DurationHow long the tool took to execute
tokens_used: Option<u32>Optional token count (for LLM-based tools)
timestamp: StringISO 8601 timestamp of execution
tool_name: StringName of the tool that produced this result
Implementations§
Source§impl ToolResult
impl ToolResult
Sourcepub fn new(
tool_name: &str,
args: &Value,
output: Value,
execution_time: Duration,
) -> Self
pub fn new( tool_name: &str, args: &Value, output: Value, execution_time: Duration, ) -> Self
Create a new tool result with automatic hash computation.
The hash is computed from a deterministic JSON representation of:
- Tool name
- Input arguments
- Output value
- Timestamp
§Arguments
tool_name- Name of the toolargs- Input arguments that were passed to the tooloutput- Result value from the toolexecution_time- How long execution took
§Security
The timestamp is captured at creation time and included in the hash to prevent replay attacks where an old result could be substituted.
Sourcepub fn with_tokens(self, tokens: u32) -> Self
pub fn with_tokens(self, tokens: u32) -> Self
Add token usage information
Sourcepub fn verify(&self, args: &Value) -> bool
pub fn verify(&self, args: &Value) -> bool
Verify that the hash matches the content
§Returns
true if the hash is valid for the current content, false otherwise.
A false result indicates potential tampering.
Sourcepub fn execution_ms(&self) -> u128
pub fn execution_ms(&self) -> u128
Get execution time in milliseconds
Trait Implementations§
Source§impl Clone for ToolResult
impl Clone for ToolResult
Source§fn clone(&self) -> ToolResult
fn clone(&self) -> ToolResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ToolResult
impl Debug for ToolResult
Source§impl<'de> Deserialize<'de> for ToolResult
impl<'de> Deserialize<'de> for ToolResult
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ToolResult
impl RefUnwindSafe for ToolResult
impl Send for ToolResult
impl Sync for ToolResult
impl Unpin for ToolResult
impl UnwindSafe for ToolResult
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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