Skip to content

Commit 747023b

Browse files
Zhang-986N3kox
andauthored
fix(adk): preserve streaming tool output during reduction (#1090)
* fix(adk): preserve streaming tool output during reduction * test(adk): cover streaming truncation terminal paths * refactor(adk): streamline stream truncation handling --------- Co-authored-by: xuzhaonan <xuzhaonan@bytedance.com>
1 parent ad1d0af commit 747023b

3 files changed

Lines changed: 1071 additions & 4 deletions

File tree

adk/middlewares/reduction/consts.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
// Package reduction provides middlewares to trim context and clear tool results.
1818
package reduction
1919

20-
import "github.com/cloudwego/eino/adk/internal"
20+
import (
21+
"fmt"
22+
23+
"github.com/cloudwego/eino/adk/internal"
24+
)
2125

2226
const (
2327
truncFmt = `<persisted-output>
@@ -40,6 +44,15 @@ Preview (last {preview_size}):
4044
</persisted-output>`
4145
)
4246

47+
const (
48+
streamTruncFmt = `<persisted-output>
49+
Output truncated after {preview_size} bytes were streamed. {offload_notify} {error_msg_notify}
50+
</persisted-output>`
51+
streamTruncFmtZh = `<persisted-output>
52+
输出结果在流式传输 {preview_size} 字节后被截断。{offload_notify} {error_msg_notify}
53+
</persisted-output>`
54+
)
55+
4356
const (
4457
clearWithOffloadingFmt = `<persisted-output>Tool result saved to: {file_path}
4558
Use {read_tool_name} to view</persisted-output>`
@@ -61,6 +74,30 @@ func getTruncFmt() string {
6174
})
6275
}
6376

77+
func getStreamTruncFmt() string {
78+
return internal.SelectPrompt(internal.I18nPrompts{
79+
English: streamTruncFmt,
80+
Chinese: streamTruncFmtZh,
81+
})
82+
}
83+
84+
func formatStreamOffloadSavedNotify(filePath string) string {
85+
return fmt.Sprintf(internal.SelectPrompt(internal.I18nPrompts{
86+
English: "Full output saved to: %s.",
87+
Chinese: "完整输出保存到: %s。",
88+
}), filePath)
89+
}
90+
91+
func formatStreamOffloadFailedNotify(err error) string {
92+
if err == nil {
93+
return ""
94+
}
95+
return fmt.Sprintf(internal.SelectPrompt(internal.I18nPrompts{
96+
English: "Failed to save full output: %v.",
97+
Chinese: "完整输出保存失败: %v。",
98+
}), err)
99+
}
100+
64101
func getClearWithOffloadingFmt() string {
65102
return internal.SelectPrompt(internal.I18nPrompts{
66103
English: clearWithOffloadingFmt,

0 commit comments

Comments
 (0)