Package org.bsc.spring.agentexecutor
Class ToolService
java.lang.Object
org.bsc.spring.agentexecutor.ToolService
Service class responsible for managing tools and their callbacks.
-
Constructor Summary
ConstructorDescriptionToolService
(org.springframework.context.ApplicationContext applicationContext) Constructs a new instance of ToolService with the given ApplicationContext. -
Method Summary
Modifier and TypeMethodDescription<I,
O> Optional<AgentFunctionCallbackWrapper<I, O>> agentFunction
(@NonNull String name) Retrieves a specific function callback wrapper by name.List<org.springframework.ai.model.function.FunctionCallback>
Retrieves all registered function callback wrappers.org.springframework.ai.chat.messages.ToolResponseMessage
buildToolResponseMessage
(org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse response) Builds a tool response message from a given tool response.CompletableFuture<org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse>
executeFunction
(org.springframework.ai.chat.messages.AssistantMessage.ToolCall toolCall) Executes a function based on the given tool call with default context map.CompletableFuture<org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse>
executeFunction
(org.springframework.ai.chat.messages.AssistantMessage.ToolCall toolCall, Map<String, Object> toolContextMap) Executes a function based on the given tool call and context map.<O> Optional<O>
getFunctionResult
(org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse response) Retrieves the result of a function based on the given tool response.
-
Constructor Details
-
ToolService
public ToolService(org.springframework.context.ApplicationContext applicationContext) Constructs a new instance of ToolService with the given ApplicationContext.- Parameters:
applicationContext
- The application context to retrieve function callback wrappers.
-
-
Method Details
-
agentFunctionsCallback
Retrieves all registered function callback wrappers.- Returns:
- A list of function callback wrappers.
-
agentFunction
public <I,O> Optional<AgentFunctionCallbackWrapper<I,O>> agentFunction(@NonNull @NonNull String name) Retrieves a specific function callback wrapper by name.- Parameters:
name
- The name of the function callback to retrieve.- Returns:
- An optional containing the function callback wrapper, or an empty optional if not found.
-
getFunctionResult
public <O> Optional<O> getFunctionResult(@NonNull org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse response) Retrieves the result of a function based on the given tool response.- Parameters:
response
- The tool response message.- Returns:
- An optional containing the function result, or an empty optional if no function is found.
-
buildToolResponseMessage
public org.springframework.ai.chat.messages.ToolResponseMessage buildToolResponseMessage(@NonNull org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse response) Builds a tool response message from a given tool response.- Parameters:
response
- The tool response to convert into a message.- Returns:
- A new ToolResponseMessage containing the provided response.
-
executeFunction
public CompletableFuture<org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse> executeFunction(org.springframework.ai.chat.messages.AssistantMessage.ToolCall toolCall, Map<String, Object> toolContextMap) Executes a function based on the given tool call and context map.- Parameters:
toolCall
- The tool call to execute.toolContextMap
- The context map for the tool execution.- Returns:
- A CompletableFuture containing the result of the executed function.
-
executeFunction
public CompletableFuture<org.springframework.ai.chat.messages.ToolResponseMessage.ToolResponse> executeFunction(org.springframework.ai.chat.messages.AssistantMessage.ToolCall toolCall) Executes a function based on the given tool call with default context map.- Parameters:
toolCall
- The tool call to execute.- Returns:
- A CompletableFuture containing the result of the executed function.
-