Package org.bsc.langgraph4j.agent
Class ToolResponseBuilder
java.lang.Object
org.bsc.langgraph4j.agent.ToolResponseBuilder
- Direct Known Subclasses:
LC4jToolResponseBuilder,SpringAIToolResponseBuilder
A builder class to construct a
Command and update the execution context.
This builder is used within a tool/action to specify the next node to execute (gotoNode(String))
and any state updates (update(Map)). The resulting Command is then
placed into the shared context, typically within an AtomicReference, for the
graph execution engine to process.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionToolResponseBuilder(Map<String, Object> context) Constructs a new ToolResponseBuilder. -
Method Summary
Modifier and TypeMethodDescriptionfinal <T> Tbuild(T result) Deprecated, for removal: This API element is subject to removal in a future version.final <T> TbuildAndReturn(T result) Builds theCommand, updates the context, and returns the provided result.final voidBuilds theCommandand sets it in the context.final ToolResponseBuilderSpecifies the name of the next node to transition to in the graph.final ToolResponseBuilderProvides a map of key-value pairs to update the shared state.
-
Field Details
-
COMMAND_RESULT
- See Also:
-
-
Constructor Details
-
ToolResponseBuilder
Constructs a new ToolResponseBuilder.- Parameters:
context- the shared execution context map
-
-
Method Details
-
gotoNode
Specifies the name of the next node to transition to in the graph.- Parameters:
gotoNode- the name of the target node- Returns:
- this builder instance for chaining
-
update
Provides a map of key-value pairs to update the shared state.- Parameters:
update- a map containing state updates- Returns:
- this builder instance for chaining
-
build
Deprecated, for removal: This API element is subject to removal in a future version.UsebuildAndReturn(Object)instead. This method will be removed in a future version.Builds theCommand, updates the context, and returns the provided result.- Type Parameters:
T- the type of the result- Parameters:
result- the result to return from the tool/action method- Returns:
- the provided result, allowing for a fluent return from the calling method
-
buildAndReturn
public final <T> T buildAndReturn(T result) Builds theCommand, updates the context, and returns the provided result. This is useful for returning a value from a tool execution while also setting the command.- Type Parameters:
T- the type of the result- Parameters:
result- the result to return from the tool/action method- Returns:
- the provided result, allowing for a fluent return from the calling method
-
buildAndSet
public final void buildAndSet()Builds theCommandand sets it in the context. This method finds anAtomicReference<Command>in the context using thecommandResultKey, creates a newCommandfrom the builder's state, and sets it on the reference.- Throws:
IllegalStateException- if the object atcommandResultKeyin the context is not of the expected typeAtomicReference<Command>.
-
buildAndReturn(Object)instead.