Class PatchToolCallsInterceptor
java.lang.Object
com.alibaba.cloud.ai.graph.agent.interceptor.ModelInterceptor
com.alibaba.cloud.ai.graph.agent.extension.interceptor.PatchToolCallsInterceptor
- All Implemented Interfaces:
Interceptor
Middleware to patch dangling tool calls in the messages history.
This interceptor handles situations where an AI message contains tool calls that don't have corresponding ToolResponseMessages in the conversation history. This can happen when tool execution is interrupted or when new messages arrive before tool responses can be added.
The interceptor automatically adds cancellation messages for any dangling tool calls, preventing errors when the conversation is sent to the model.
Example usage:
PatchToolCallsInterceptor interceptor = PatchToolCallsInterceptor.builder().build(); agent.addInterceptor(interceptor);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating PatchToolCallsInterceptor instances. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()getName()interceptModel(ModelRequest request, ModelCallHandler handler) Wrap a model call with custom logic.Methods inherited from class com.alibaba.cloud.ai.graph.agent.interceptor.ModelInterceptor
getTools
-
Method Details
-
builder
-
getName
-
interceptModel
Description copied from class:ModelInterceptorWrap a model call with custom logic. Implementations can: - Modify the request before calling the handler - Call the handler multiple times (retry logic) - Modify the response after handler returns - Handle exceptions and provide fallbacks- Specified by:
interceptModelin classModelInterceptor- Parameters:
request- The model requesthandler- The next handler in the chain (or base handler)- Returns:
- The model response
-