feat: 工具执行流式输出预览
- ToolEvent 新增 PROGRESS 阶段,工具可在执行中报告进度 - ToolContext 添加 progressCallback,工具可通过 reportProgress() 报告输出行 - BashTool 在读取每行输出时实时报告进度 - AgentLoop 在工具执行前设置进度回调,执行后清除 - ToolCallMsg 支持 outputLines 字段,保留最后 5 行流式预览 - 运行中的工具在消息区显示实时输出(灰色,截断至 120 字符) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -413,7 +413,18 @@ public class AgentLoop {
|
||||
}
|
||||
|
||||
if (permitted) {
|
||||
result = adapter.call(toolArgs);
|
||||
// 设置进度回调,将工具输出行转发为 PROGRESS 事件
|
||||
final String tn = toolName;
|
||||
final String ta = toolArgs;
|
||||
if (onToolEvent != null) {
|
||||
toolContext.setProgressCallback(line ->
|
||||
onToolEvent.accept(new ToolEvent(tn, ToolEvent.Phase.PROGRESS, ta, line)));
|
||||
}
|
||||
try {
|
||||
result = adapter.call(toolArgs);
|
||||
} finally {
|
||||
toolContext.setProgressCallback(null);
|
||||
}
|
||||
} else {
|
||||
result = "Permission denied: User rejected this operation";
|
||||
log.info("[{}] User denied tool execution", toolName);
|
||||
@@ -561,6 +572,6 @@ public class AgentLoop {
|
||||
|
||||
/** 工具事件,用于 UI 展示 */
|
||||
public record ToolEvent(String toolName, Phase phase, String arguments, String result) {
|
||||
public enum Phase { START, END }
|
||||
public enum Phase { START, PROGRESS, END }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user