Class ToolEmulatorInterceptor
java.lang.Object
com.alibaba.cloud.ai.graph.agent.interceptor.ToolInterceptor
com.alibaba.cloud.ai.graph.agent.interceptor.toolemulator.ToolEmulatorInterceptor
- All Implemented Interfaces:
Interceptor
Tool interceptor that emulates specified tools using an LLM instead of executing them.
This interceptor allows selective emulation of tools for testing purposes.
By default (when tools=null), all tools are emulated. You can specify which
tools to emulate by passing a list of tool names.
Example:
// Emulate all tools (default behavior)
ToolEmulatorInterceptor emulator = ToolEmulatorInterceptor.builder()
.model(chatModel)
.build();
// Emulate specific tools by name
ToolEmulatorInterceptor emulator = ToolEmulatorInterceptor.builder()
.model(chatModel)
.addTool("get_weather")
.addTool("get_user_location")
.build();
// Emulate all except specified tools
ToolEmulatorInterceptor emulator = ToolEmulatorInterceptor.builder()
.model(chatModel)
.emulateAllTools(false) // Only emulate specified tools
.addTool("expensive_api")
.build();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()getName()interceptToolCall(ToolCallRequest request, ToolCallHandler handler) Wrap a tool call with custom logic.
-
Method Details
-
builder
-
getName
-
interceptToolCall
Description copied from class:ToolInterceptorWrap a tool 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 - Add caching, logging, monitoring, etc.- Specified by:
interceptToolCallin classToolInterceptor- Parameters:
request- The tool call requesthandler- The next handler in the chain (or base handler)- Returns:
- The tool call response
-