Package dev.langchain4j.service.tool
Interface ToolExecutionErrorHandler
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Handler for
ToolExecutionException
s thrown by a ToolExecutor
.
Currently, there are two ways to handle errors:
1. Throw an exception: this will stop the AI service flow.
2. Return a text message (e.g., an error description) that will be sent back to the LLM, allowing it to respond appropriately (for example, by correcting the error and retrying).
- Since:
- 1.4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionhandle
(Throwable error, ToolErrorContext context) Handles an error that occurred during tool execution.
-
Method Details
-
handle
Handles an error that occurred during tool execution.This method should either throw an exception or return a
ToolErrorHandlerResult.text(String)
, which will be sent to the LLM as the result of the tool execution.- Parameters:
error
- The actual error that occurred.context
- The context in which the error occurred.- Returns:
- The result of error handling.
-