ToolResultConverter
public interface ToolResultConverter
源码Source
io/agentscope/core/tool/ToolResultConverter.java:48–58定义工具结果转换器契约的接口。位于 io.agentscope.core.tool 包。核心成员包括 convert。
Converts tool method return values to ToolResultBlock. Custom implementations can override conversion logic for specific tools.
This interface allows users to customize how tool results are converted and presented to LLMs. Implementations can control JSON serialization, add metadata, filter sensitive data, or compress large outputs.
Usage Example:
`public class CustomConverter implements ToolResultConverter {
@Override
public ToolResultBlock convert(Object result, Type returnType) {
// Custom conversion logic
return ToolResultBlock.of(...);
}
}
@Tool(
name = "my_tool",
converter = CustomConverter.class
)
public String myTool() { ... }
`
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public ToolResultBlock convert(Object result, Type returnType) | 转换工具调用结果到 ToolResultBlock。 Convert tool call result to ToolResultBlock. |
方法详情Method Detail
convert
public ToolResultBlock convert(Object result, Type returnType)
转换工具调用结果到 ToolResultBlock。
Convert tool call result to ToolResultBlock.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
result | Object | 结果(类型 `Object`)。the tool call result (may be null) |
returnType | Type | return 类型(类型 `Type`)。the return type of the tool method (may be null) |
ToolResultBlock返回ToolResultBlock。ToolResultBlock containing the converted result (never null)
源码Source
io/agentscope/core/tool/ToolResultConverter.java:57