-
Notifications
You must be signed in to change notification settings - Fork 259
Open
Description
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:
- Write streaming output to a shared buffer
- Allow frontend to poll/subscribe to this buffer by a unique session ID
- The natural session ID is
toolCallId, which is already available inToolUseBlock
Without access to toolCallId, tools must generate random UUIDs, causing frontend-backend ID mismatch.
Proposed Solution
Add a default method to ToolEmitter interface:
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:
@Override
public String getToolCallId() {
return toolUseBlock != null ? toolUseBlock.getId() : null;
}Use Cases
- Terminal/Bash Tools: Write output to a shared
TerminalBufferkeyed bytoolCallId, allowing frontend to display real-time output - Long-running Tasks: Track progress and allow cancellation by
toolCallId - 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!
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Backlog