接口 ToolEmitter
- 所有已知实现类:
NoOpToolEmitter
public interface ToolEmitter
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");
}
-
方法概要
修饰符和类型方法说明voidemit(ToolResultBlock chunk) Emit a streaming response chunk during tool execution.
-
方法详细资料
-
emit
Emit a streaming response chunk during tool execution.This method sends intermediate messages to registered hooks via
onToolChunk(). The emitted chunks do NOT affect what the LLM receives - only the tool method's return value is sent to the LLM.- 参数:
chunk- The chunk to emit
-