Skip to content

Commit 9dfb2e8

Browse files
authored
Merge pull request #2331 from shaj13/shaj13/sesid
session: add WithID option for custom session IDs
2 parents 3fac361 + 6bfc316 commit 9dfb2e8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/session/session.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ func WithParentID(parentID string) Opt {
579579
}
580580
}
581581

582+
// WithID sets the session ID. If not set, a UUID will be generated.
583+
func WithID(id string) Opt {
584+
return func(s *Session) {
585+
s.ID = id
586+
}
587+
}
588+
582589
// WithExcludedTools sets tool names that should be filtered out of the agent's
583590
// tool list for this session. This prevents recursive tool calls in skill
584591
// sub-sessions.
@@ -647,11 +654,8 @@ func (s *Session) OwnCost() float64 {
647654

648655
// New creates a new agent session
649656
func New(opts ...Opt) *Session {
650-
sessionID := uuid.New().String()
651-
slog.Debug("Creating new session", "session_id", sessionID)
652-
653657
s := &Session{
654-
ID: sessionID,
658+
ID: uuid.New().String(),
655659
CreatedAt: time.Now(),
656660
SendUserMessage: true,
657661
}
@@ -660,6 +664,7 @@ func New(opts ...Opt) *Session {
660664
opt(s)
661665
}
662666

667+
slog.Debug("Creating new session", "session_id", s.ID)
663668
return s
664669
}
665670

0 commit comments

Comments
 (0)