feat: add date-based weather forecasts and dynamic time context

This commit is contained in:
loveuer committed 2026-11-18 11:30:38 +08:00
1 parent a394f22d77
commit 975352c7d6
12 files changed
+607 -15

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
package agent
import (
"context"
"fmt"
"time"
"github.com/cloudwego/eino/adk"
"github.com/cloudwego/eino/schema"
)
func genModelInput(_ context.Context, instruction string, input *adk.AgentInput) ([]adk.Message, error) {
messages := []adk.Message{schema.SystemMessage(timedInstruction(instruction, time.Now()))}
return append(messages, input.Messages...), nil
}
// timedInstruction 每轮生成时间信息,避免使用进程启动时的旧日期。
func timedInstruction(instruction string, now time.Time) string {
now = now.In(time.FixedZone("Asia/Shanghai", 8*60*60))
weekdays := [...]string{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}
// 按周一至周日确定当前周,给模型明确的日期参照。
weekday := (int(now.Weekday()) + 6) % 7
saturday := now.AddDate(0, 0, 5-weekday)
return instruction + fmt.Sprintf(`
当前日期:%s,%s,时区:Asia/Shanghai(UTC+08:00)。
明天:%s;本周六:%s;本周日:%s。
查询天气时将相对时间换算为 YYYY-MM-DD,日期参数只能是一个完整日期,不要把多个日期拼进同一个字段。
查询本周末两天时,日期参数示例:{"start_date":"%s","end_date":"%s"},location 使用用户指定的地点。日期存在歧义时先询问。
未提供查询地点且历史中也没有时,先询问,不要猜测。收到预报后直接根据结果回答,不重复查询相同日期;无法获取时如实说明,不用当前天气代替目标日期预报。`,
now.Format(time.DateOnly), weekdays[now.Weekday()], now.AddDate(0, 0, 1).Format(time.DateOnly),
saturday.Format(time.DateOnly), saturday.AddDate(0, 0, 1).Format(time.DateOnly),
saturday.Format(time.DateOnly), saturday.AddDate(0, 0, 1).Format(time.DateOnly))
}