From 6bfc31647f57b238fd69c8cfe1f046aed315766d Mon Sep 17 00:00:00 2001 From: shaj13 Date: Mon, 6 Apr 2026 16:00:34 +0000 Subject: [PATCH] session: add WithID option for custom session IDs Apply options before generating UUID, allowing callers to set a custom session ID via WithID. If no ID is provided, a UUID is generated. --- pkg/session/session.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/session/session.go b/pkg/session/session.go index 808075ca0..979ea95f8 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -579,6 +579,13 @@ func WithParentID(parentID string) Opt { } } +// WithID sets the session ID. If not set, a UUID will be generated. +func WithID(id string) Opt { + return func(s *Session) { + s.ID = id + } +} + // WithExcludedTools sets tool names that should be filtered out of the agent's // tool list for this session. This prevents recursive tool calls in skill // sub-sessions. @@ -647,11 +654,8 @@ func (s *Session) OwnCost() float64 { // New creates a new agent session func New(opts ...Opt) *Session { - sessionID := uuid.New().String() - slog.Debug("Creating new session", "session_id", sessionID) - s := &Session{ - ID: sessionID, + ID: uuid.New().String(), CreatedAt: time.Now(), SendUserMessage: true, } @@ -660,6 +664,7 @@ func New(opts ...Opt) *Session { opt(s) } + slog.Debug("Creating new session", "session_id", s.ID) return s }