返回 DeepSeek-Reasonix
message_origin.go
根目录 / internal / agent / message_origin.go
1 package agent
2
3 import (
4 "context"
5
6 "reasonix/internal/provider"
7 )
8
9 type inputMessageOriginKey struct{}
10
11 // WithInputMessageOrigin marks the user-role message Agent.Run will persist.
12 // Controllers use host origin only for synthetic continuation runs.
13 func WithInputMessageOrigin(ctx context.Context, origin provider.MessageOrigin) context.Context {
14 if ctx == nil {
15 ctx = context.Background()
16 }
17 return context.WithValue(ctx, inputMessageOriginKey{}, origin)
18 }
19
20 func inputMessageOrigin(ctx context.Context) provider.MessageOrigin {
21 if ctx != nil {
22 if origin, ok := ctx.Value(inputMessageOriginKey{}).(provider.MessageOrigin); ok && origin == provider.MessageOriginHost {
23 return origin
24 }
25 }
26 return provider.MessageOriginUser
27 }
28
29 // HostGeneratedUserMessage constructs a provider-visible user-role protocol
30 // message whose durable provenance prevents it from being mistaken for user
31 // intent by transcripts or completion evidence.
32 func HostGeneratedUserMessage(content string) provider.Message {
33 return provider.Message{Role: provider.RoleUser, Origin: provider.MessageOriginHost, Content: content}
34 }
35
35 lines GO