agentscope-ai / agentscope-ai/agentscope-java

Feature Request: Add getToolCallId() to ToolEmitter interface

未關閉
#695 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area/core/tool enhancement
主要語言
Java
星號
5.6k
分支
1.3k
平均合併
4 天 12 小時
30 天內合併 PR
77

描述

## Background

When implementing streaming tools (e.g., bash/terminal execution), tools need to correlate their output with the frontend UI. The `toolCallId` is the natural identifier for this correlation, but currently tools have no way to access it through the `ToolEmitter` interface.

## Problem

Tools like `BashTool` need to:
1. Write streaming output to a shared buffer
2. Allow frontend to poll/subscribe to this buffer by a unique session ID
3. The natural session ID is `toolCallId`, which is already available in `ToolUseBlock`

Without access to `toolCallId`, tools must generate random UUIDs, causing frontend-backend ID mismatch.

## Proposed Solution

Add a default method to `ToolEmitter` interface:

```java
public interface ToolEmitter {
void emit(ToolResultBlock chunk);

/**
* Returns the tool call ID associated with this emitter.
* This allows tools to correlate their output with frontend components.
*
* @return the tool call ID, or null if not available
*/
default String getToolCallId() {
return null;
}
}
```

And implement it in `DefaultToolEmitter`:

```java
@Override
public String getToolCallId() {
return toolUseBlock != null ? toolUseBlock.getId() : null;
}
```

## Use Cases

1. **Terminal/Bash Tools**: Write output to a shared `TerminalBuffer` keyed by `toolCallId`, allowing frontend to display real-time output
2. **Long-running Tasks**: Track progress and allow cancellation by `toolCallId`
3. **Streaming File Operations**: Correlate file upload/download progress with UI components

## Backward Compatibility

The default method returns `null`, ensuring existing implementations continue to work without modification.

## Current Workaround

We've implemented this locally, but would prefer official framework support for maintainability.

---

Thank you for considering this feature request!

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。