AS AgentScopeAPI 手册 / API Reference

ToolEmitter

public interface ToolEmitter
源码Source 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 ToolParam annotation 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.

参数Parameters
名称Name类型Type说明Description
chunkToolResultBlock分块到发出。The chunk to emit
源码Source io/agentscope/core/tool/ToolEmitter.java:70
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.