ToolEmitter
public interface ToolEmitter
io/agentscope/core/tool/ToolEmitter.java:59–71定义工具 Emitter契约的接口。位于 io.agentscope.core.tool 包。核心成员包括 emit。
Interface for emitting streaming responses during tool execution.
Tool methods can declare a ToolEmitter parameter to send intermediate progress updates and
messages during execution. These streaming chunks are delivered to registered hooks via
onActingChunk() events but are NOT sent to the LLM. Only the final return value of the
tool method is sent to the LLM as the tool result.
Key Characteristics:
-
ToolEmitter is auto-injected by the framework - no
ToolParamannotation needed -
Emitted chunks go to hooks (for monitoring/logging), not to the LLM
-
Useful for long-running tools to provide progress feedback
-
Does not affect the tool schema visible to the LLM
Usage Example:
`@Tool(name = "long_task", description = "Execute a long running task")
public ToolResultBlock execute(
@ToolParam(name = "input") String input,
ToolEmitter emitter // Automatically injected by framework
) {
emitter.emit(ToolResultBlock.text("Starting task..."));
// Step 1
processStep1(input);
emitter.emit(ToolResultBlock.text("Step 1 completed"));
// Step 2
processStep2(input);
emitter.emit(ToolResultBlock.text("Step 2 completed"));
// Final result (this is what the LLM sees)
return ToolResultBlock.text("Task completed successfully");
}
`
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void emit(ToolResultBlock chunk) | 设置发出。 Emit a streaming response chunk during tool execution. |
方法详情Method Detail
emit
public void emit(ToolResultBlock chunk)
设置发出。
Emit a streaming response chunk during tool execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
chunk | ToolResultBlock | 分块到发出。The chunk to emit |
io/agentscope/core/tool/ToolEmitter.java:70