feat: add travel guide Graph with progressive output and image confirmation

This commit is contained in:
loveuer committed 2026-11-18 13:53:13 +08:00
1 parent fd3dcbe104
commit 73f6f0901e
13 files changed
+577 -26

No files matched your search

+32 -2
View File
@@ -13,7 +13,7 @@ import (
"github.com/cloudwego/eino/schema"
)
// readResponse 消费事件流,主助手正文和工具执行状态分别输出。
// readResponse 消费事件流,正文或流程结果与执行状态分别输出。
func readResponse(events *adk.AsyncIterator[*adk.AgentEvent], onText, onStatus func(string)) (string, *adk.InterruptInfo, error) {
var interrupted *adk.InterruptInfo
reply := ""
@@ -37,6 +37,14 @@ func readResponse(events *adk.AsyncIterator[*adk.AgentEvent], onText, onStatus f
interrupted = event.Action.Interrupted
continue
}
if event.Output != nil {
if progress, ok := event.Output.CustomizedOutput.(travelProgress); ok {
if onText != nil {
onText(string(progress))
}
continue
}
}
if event.Output == nil || event.Output.MessageOutput == nil {
continue
}
@@ -56,13 +64,35 @@ func readResponse(events *adk.AsyncIterator[*adk.AgentEvent], onText, onStatus f
}
if output.Role == schema.Tool {
message := fmt.Sprintf("%s:%s 执行完成", event.AgentName, output.ToolName)
if output.ToolName == "generate_image" {
if output.ToolName == "generate_image" || output.ToolName == travelToolName {
var result model.ImageResult
if json.Unmarshal([]byte(text), &result) == nil && result.Path != "" {
message += ",图片:" + result.Path
}
}
status(message)
if output.ToolName == travelToolName {
// 固定流程直接返回结果,避免模型再次改写或省略已完成的行程。
var guide model.TravelGuide
if err := json.Unmarshal([]byte(text), &guide); err != nil {
return "", nil, err
}
reply = guide.Problem
if reply == "" {
if guide.Plan == "" || guide.Path == "" {
return "", nil, fmt.Errorf("攻略流程未返回完整行程和图片路径")
}
reply = travelWeatherText(guide.Weather) + guide.Plan + "\n\n攻略图:" + guide.Path
}
if onText != nil {
if guide.Problem != "" {
onText(guide.Problem)
} else {
// 天气和行程已在确认前展示,完成后只补充实际图片路径。
onText("\n攻略图:" + guide.Path)
}
}
}
}
}
}