New creates a new agent session
(opts ...Opt)
| 1018 | |
| 1019 | // New creates a new agent session |
| 1020 | func New(opts ...Opt) *Session { |
| 1021 | s := &Session{ |
| 1022 | SendUserMessage: true, |
| 1023 | } |
| 1024 | |
| 1025 | for _, opt := range opts { |
| 1026 | opt(s) |
| 1027 | } |
| 1028 | |
| 1029 | // Generate the ID and creation time after options run so that |
| 1030 | // WithClock/WithIDGen (and WithID) can influence them. WithID short- |
| 1031 | // circuits the generator when an explicit ID was provided. |
| 1032 | if s.ID == "" { |
| 1033 | s.ID = s.newID() |
| 1034 | } |
| 1035 | s.CreatedAt = s.now() |
| 1036 | |
| 1037 | slog.Debug("Creating new session", "session_id", s.ID) |
| 1038 | return s |
| 1039 | } |
| 1040 | |
| 1041 | func markLastMessageAsCacheControl(messages []chat.Message) { |
| 1042 | if len(messages) > 0 { |