Class ToolExecution
java.lang.Object
dev.langchain4j.service.tool.ToolExecution
Represents the execution of a tool, including the request and the result.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionReturns the attributes associated with the tool execution.static ToolExecution.Builderbuilder()duration()Returns the duration of the tool execution, ornullif timing was not recorded.booleanReturns the time when the tool execution finished, ornullif not recorded.booleanIndicates whether the tool execution result represents an error.inthashCode()Returns the invocation context of the tool execution.booleanWhether a tool output guardrail replaced the result of a tool that ran: with a rewrite, or with the message of a non-fatal failure.request()Returns the request of the tool execution.result()Returns the tool execution result as text.Returns the contents of the tool execution result.@Nullable ObjectReturns the tool execution result as object.Returns the time when the tool execution started, ornullif not recorded.toString()
-
Method Details
-
request
Returns the request of the tool execution.- Returns:
- the request of the tool execution.
-
result
Returns the tool execution result as text.- Returns:
- the result of the tool execution.
- See Also:
-
resultContents
Returns the contents of the tool execution result. For text-only results, returns a singleton list containing aTextContent.- Since:
- 1.13.0
- See Also:
-
resultObject
Returns the tool execution result as object. This object is the actual value returned by the tool.- Returns:
- the result of the tool execution, or
nullwhen the tool returned none, and when a tool output guardrail rewrote or rejected the result (the object no longer matches what the LLM sees):isResultReplaced()tells the two apart - See Also:
-
attributes
Returns the attributes associated with the tool execution. Attributes can be set by the tool itself or, in case of MCP tools, originate from the_metafield of the tool call response. They are not sent to the LLM.- Returns:
- an unmodifiable map of attributes, or an empty map if none were set.
- Since:
- 1.19.0
-
hasFailed
public boolean hasFailed()Indicates whether the tool execution result represents an error. -
startTime
Returns the time when the tool execution started, ornullif not recorded. -
finishTime
Returns the time when the tool execution finished, ornullif not recorded. -
duration
Returns the duration of the tool execution, ornullif timing was not recorded. -
invocationContext
Returns the invocation context of the tool execution. -
isResultReplaced
Whether a tool output guardrail replaced the result of a tool that ran: with a rewrite, or with the message of a non-fatal failure.resultObject()then no longer holds the object the tool returned (it is dropped, since it does not match what the LLM sees), even when the tool returned one. That is also the case when an output guardrail rewrote the error result of a tool that failed on its own.falsewhen no guardrail replaced the result (also for a tool that failed on its own and whose error result was sent as it is), and when an input guardrail rejected the call (the tool did not run, andhasFailed()istrue). A fatal guardrail failure gives no execution.- Returns:
- whether a tool output guardrail replaced the result of the tool
- Since:
- 1.25.0
-
equals
-
hashCode
-
toString
-
builder
-