返回 DeepSeek-Reasonix
steer_record.go
根目录 / internal / agent / steer_record.go
1 package agent
2
3 import (
4 "context"
5 "fmt"
6
7 "reasonix/internal/event"
8 "reasonix/internal/i18n"
9 "reasonix/internal/provider"
10 )
11
12 // UnappliedSteerNotice returns the durable warning shown for guidance that was
13 // accepted during an abnormal turn exit but never reached a provider request.
14 // The user's guidance rides the format's trailing %s so fronts can split it
15 // back out at the first newline.
16 func UnappliedSteerNotice(text string) string {
17 return fmt.Sprintf(i18n.M.UnappliedSteerFmt, text)
18 }
19
20 // RecordUnappliedSteer stores guidance that could not affect its intended
21 // in-flight turn. The orphan-tool sentinel makes older readers drop the record
22 // during wire normalization, while current readers use LocalOnly to exclude it
23 // before every provider request. itemID correlates the notice with the durable
24 // session inbox entry when one exists.
25 func (a *Agent) RecordUnappliedSteer(text string, itemID ...string) {
26 if a == nil || a.sess.conversation == nil {
27 return
28 }
29 id := ""
30 if len(itemID) > 0 {
31 id = itemID[0]
32 }
33 _ = a.appendCommittedMessages(context.Background(), "unapplied-steer", provider.Message{
34 Role: provider.RoleTool,
35 Content: a.withTurnPreferences(midTurnSteerMessage(text)),
36 ToolCallID: provider.LocalOnlyToolID,
37 Name: provider.LocalOnlyToolName,
38 LocalOnly: true,
39 })
40 a.svc.sink.Emit(event.Event{
41 Kind: event.Notice,
42 Level: event.LevelWarn,
43 Code: event.NoticeCodeUnappliedSteer,
44 Text: UnappliedSteerNotice(text),
45 ItemID: id,
46 })
47 }
48
48 lines GO