Class ToolExecutionResult
The result can be provided in three mutually exclusive ways via the builder:
ToolExecutionResult.Builder.resultText(String)— a text result, stored internally as a singleTextContent.ToolExecutionResult.Builder.resultTextSupplier(Supplier)— a lazily computed text result. The supplier is invoked on first access toresultContents()orresultText()and the result is cached.ToolExecutionResult.Builder.resultContents(List)— a result containing any combination ofContentelements (e.g.TextContent,ImageContent).
Regardless of which builder method was used, the canonical accessor is resultContents(),
which always returns a List<Content>. The convenience method resultText() can be used
when the result is known to be a single TextContent; it throws IllegalStateException otherwise.
- Since:
- 1.6.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns attributes associated with the tool execution.static ToolExecutionResult.Builderbuilder()booleaninthashCode()booleanisError()Returns whether the tool execution resulted in an error.result()Returns the raw object returned by the tool method.Returns the contents of the tool execution result that will be sent to the LLM.Returns the tool execution result as a plain text string.toString()
-
Constructor Details
-
ToolExecutionResult
-
-
Method Details
-
isError
public boolean isError()Returns whether the tool execution resulted in an error.- Returns:
trueif the tool execution failed,falseotherwise.
-
result
-
resultText
Returns the tool execution result as a plain text string. This is a convenience method for when the result is known to be a singleTextContent.- Returns:
- the text of the single
TextContentelement. - Throws:
IllegalStateException- if the result contains non-text or multiple content elements. UseresultContents()instead.- See Also:
-
resultContents
Returns the contents of the tool execution result that will be sent to the LLM.When built with
ToolExecutionResult.Builder.resultTextSupplier(Supplier), the contents are calculated lazily on first access and then cached.Thread-safety: in rare concurrent scenarios, the supplier may be invoked multiple times, but only one result will be cached. Suppliers should be idempotent and side-effect free.
Virtual thread friendly: uses lock-free atomic operations that do not pin carrier threads.
- Returns:
- the list of
Contentelements, nevernull. - Since:
- 1.13.0
-
attributes
Returns attributes associated with the tool execution. Attributes are propagated intoToolExecutionResultMessage.attributes()and can be persisted in aChatMemory. They are not sent to the LLM.- Returns:
- an unmodifiable map of attributes, or an empty map if none were set.
- Since:
- 1.12.0
-
equals
-
hashCode
-
toString
-
builder
-