Skip to content

armgit / ax

Public Imported from GitHub
0

Agent Executor (AX) is Google's open agentic orchestration runtime

Go

Unexport session fields

Jaana Dogan30c3c85c6ee5
diff --git a/internal/controller/gemini.go b/internal/controller/gemini.go
index a1a0078..72b47c1 100644
--- a/internal/controller/gemini.go
+++ b/internal/controller/gemini.go
@@ -229,8 +229,9 @@ func sessionToHistory(session *Session, contextWindow int) []*genai.Content {
var history []*genai.Content
// Get recent messages within context window
- startIdx := max(0, len(session.MessageHistory)-contextWindow)
- messages := session.MessageHistory[startIdx:]
+ mHistory := session.MessageHistory()
+ startIdx := max(0, len(mHistory)-contextWindow)
+ messages := mHistory[startIdx:]
// Convert each message to Gemini format
for _, msg := range messages {
diff --git a/internal/controller/session.go b/internal/controller/session.go
index 755fa26..37b151a 100644
--- a/internal/controller/session.go
+++ b/internal/controller/session.go
@@ -14,17 +14,18 @@ import (
// Session represents an agentic loop execution session.
// It maintains in-memory state and uses event log for durability.
type Session struct {
- ID string
- ActiveAgents []string
- MessageHistory []*proto.Content
- CheckpointIDs []string // Ordered list of checkpoint UUIDs
- CreatedAt time.Time
- UpdatedAt time.Time
-
- mu sync.RWMutex
- eventLog eventlog.EventLog
- currentStep int
- state proto.State
+ ID string
+
+ mu sync.RWMutex
+ eventLog eventlog.EventLog
+ currentStep int
+ state proto.State
+ activeAgents []string
+ messageHistory []*proto.Content
+ checkpointIDs []string // Ordered list of checkpoint UUIDs
+
+ createdAt time.Time
+ updatedAt time.Time
}
// EventLogFactory is a function that creates EventLog instances for sessions.
@@ -66,11 +67,11 @@ func (sm *SessionManager) NewSession(sessionID string) (*Session, error) {
ID: sessionID,
state: proto.State_STATE_UNSPECIFIED,
currentStep: 0,
- ActiveAgents: []string{},
- MessageHistory: []*proto.Content{},
- CheckpointIDs: []string{},
- CreatedAt: now,
- UpdatedAt: now,
+ activeAgents: []string{},
+ messageHistory: []*proto.Content{},
+ checkpointIDs: []string{},
+ createdAt: now,
+ updatedAt: now,
eventLog: el,
}
@@ -111,11 +112,11 @@ func (sm *SessionManager) LoadSessionFromCheckpoint(sessionID string, checkpoint
ID: sessionID,
state: proto.State_STATE_UNSPECIFIED,
currentStep: 0,
- ActiveAgents: []string{},
- MessageHistory: []*proto.Content{},
- CheckpointIDs: []string{},
- CreatedAt: time.Now(),
- UpdatedAt: time.Now(),
+ activeAgents: []string{},
+ messageHistory: []*proto.Content{},
+ checkpointIDs: []string{},
+ createdAt: time.Now(),
+ updatedAt: time.Now(),
}
targetReached := false
@@ -136,11 +137,11 @@ func (sm *SessionManager) LoadSessionFromCheckpoint(sessionID string, checkpoint
Mimetype: getStringFromData(entry.Data, "mimetype"),
Data: getStringFromData(entry.Data, "data"),
}
- session.MessageHistory = append(session.MessageHistory, content)
+ session.messageHistory = append(session.messageHistory, content)
// Track checkpoint ID if present
if entry.CheckpointID != "" {
- session.CheckpointIDs = append(session.CheckpointIDs, entry.CheckpointID)
+ session.checkpointIDs = append(session.checkpointIDs, entry.CheckpointID)
// Check if this is the target checkpoint
if checkpointID != "" && entry.CheckpointID == checkpointID {
@@ -150,7 +151,7 @@ func (sm *SessionManager) LoadSessionFromCheckpoint(sessionID string, checkpoint
}
}
- session.UpdatedAt = entry.Timestamp
+ session.updatedAt = entry.Timestamp
}
// Validate checkpoint ID if provided
@@ -225,7 +226,7 @@ func (s *Session) WriteContentIn(ctx context.Context, content *proto.Content) (s
if checkpointID != "" {
// TODO(jbd): Optimize the lookup.
- for _, existingID := range s.CheckpointIDs {
+ for _, existingID := range s.checkpointIDs {
if existingID == checkpointID {
return "", fmt.Errorf("checkpoint %s already exists", checkpointID)
}
@@ -236,11 +237,11 @@ func (s *Session) WriteContentIn(ctx context.Context, content *proto.Content) (s
return "", err
}
- s.MessageHistory = append(s.MessageHistory, content)
+ s.messageHistory = append(s.messageHistory, content)
if checkpointID != "" {
- s.CheckpointIDs = append(s.CheckpointIDs, checkpointID)
+ s.checkpointIDs = append(s.checkpointIDs, checkpointID)
}
- s.UpdatedAt = time.Now()
+ s.updatedAt = time.Now()
return checkpointID, nil
}
@@ -256,9 +257,9 @@ func (s *Session) WriteContentOut(ctx context.Context, content *proto.Content) (
return "", err
}
- s.MessageHistory = append(s.MessageHistory, content)
- s.CheckpointIDs = append(s.CheckpointIDs, checkpointID)
- s.UpdatedAt = time.Now()
+ s.messageHistory = append(s.messageHistory, content)
+ s.checkpointIDs = append(s.checkpointIDs, checkpointID)
+ s.updatedAt = time.Now()
return checkpointID, nil
}
@@ -268,7 +269,7 @@ func (s *Session) SetState(state proto.State) {
defer s.mu.Unlock()
s.state = state
- s.UpdatedAt = time.Now()
+ s.updatedAt = time.Now()
}
func (s *Session) State() proto.State {
@@ -284,7 +285,7 @@ func (s *Session) AdvanceStep() {
defer s.mu.Unlock()
s.currentStep++
- s.UpdatedAt = time.Now()
+ s.updatedAt = time.Now()
}
func (s *Session) CurrentStep() int {
@@ -294,6 +295,41 @@ func (s *Session) CurrentStep() int {
return s.currentStep
}
+func (s *Session) ActiveAgents() []string {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ return s.activeAgents
+}
+
+func (s *Session) MessageHistory() []*proto.Content {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ return s.messageHistory
+}
+
+func (s *Session) CheckpointIDs() []string {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ return s.checkpointIDs
+}
+
+func (s *Session) CreatedAt() time.Time {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ return s.createdAt
+}
+
+func (s *Session) UpdatedAt() time.Time {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ return s.updatedAt
+}
+
// Helper function to extract string from map[string]any
func getStringFromData(data map[string]any, key string) string {
if val, ok := data[key]; ok {
diff --git a/internal/server/server.go b/internal/server/server.go
index 09f721f..8ecda2d 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -89,11 +89,11 @@ func (s *Server) GetSession(ctx context.Context, req *proto.GetSessionRequest) (
Session: &proto.SessionInfo{
State: session.State(),
CurrentStep: int32(session.CurrentStep()),
- ActiveAgents: session.ActiveAgents,
- CreatedAt: timestamppb.New(session.CreatedAt),
- UpdatedAt: timestamppb.New(session.UpdatedAt),
- MessageCount: int32(len(session.MessageHistory)),
- CheckpointCount: int32(len(session.CheckpointIDs)),
+ ActiveAgents: session.ActiveAgents(),
+ CreatedAt: timestamppb.New(session.CreatedAt()),
+ UpdatedAt: timestamppb.New(session.UpdatedAt()),
+ MessageCount: int32(len(session.MessageHistory())),
+ CheckpointCount: int32(len(session.CheckpointIDs())),
},
}, nil
}