Class ToolExecutionResult.Builder
java.lang.Object
dev.langchain4j.service.tool.ToolExecutionResult.Builder
- Enclosing class:
ToolExecutionResult
- Since:
- 1.6.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattributes(Map<String, Object> attributes) Sets attributes associated with the tool execution.build()Builds aToolExecutionResult.isError(boolean isError) Sets whether the tool execution resulted in an error.Sets the raw object returned by the tool method.resultContents(List<Content> resultContents) Sets the contents of the tool execution result.resultText(String resultText) Sets the result as a text string.resultTextSupplier(Supplier<String> resultTextSupplier) Sets a supplier for lazy calculation of the result text.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
isError
Sets whether the tool execution resulted in an error.- Parameters:
isError-trueif the tool execution failed.- Returns:
- this builder.
-
result
Sets the raw object returned by the tool method. This value is not sent to the LLM.- Parameters:
result- the raw result object.- Returns:
- this builder.
-
resultText
Sets the result as a text string. The text will be wrapped into a singleTextContent. Mutually exclusive withresultTextSupplier(Supplier)andresultContents(List).- Parameters:
resultText- the text result.- Returns:
- this builder.
-
resultTextSupplier
Sets a supplier for lazy calculation of the result text. The supplier will be called on first access toToolExecutionResult.resultContents()and the result will be wrapped into a singleTextContentand cached. Mutually exclusive withresultText(String)andresultContents(List).- Parameters:
resultTextSupplier- the supplier to calculate result text on demand.- Returns:
- this builder.
- Since:
- 1.9.0
-
resultContents
Sets the contents of the tool execution result. Can contain any combination ofContentelements (e.g.TextContent,ImageContent). Mutually exclusive withresultText(String)andresultTextSupplier(Supplier).- Parameters:
resultContents- the contents.- Returns:
- this builder.
- Since:
- 1.13.0
-
attributes
Sets attributes associated with the tool execution. Attributes are propagated intoToolExecutionResultMessage.attributes()and can be persisted in aChatMemory. They are not sent to the LLM.- Parameters:
attributes- the attributes.- Returns:
- this builder.
- Since:
- 1.12.0
-
build
Builds aToolExecutionResult.- Returns:
- the built instance.
- Throws:
IllegalArgumentException- if none ofresultText,resultTextSupplier, orresultContentswas set, or if more than one was set.
-