Skip to content

Commit 5dd6ed4

Browse files
authored
Merge pull request #304 from dgageot/compute-messages-once-v1
Compute messages once
2 parents b84ef1a + ea3cb5d commit 5dd6ed4

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

pkg/runtime/runtime.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,16 @@ func (r *runtime) RunStream(ctx context.Context, sess *session.Session) <-chan E
160160
telemetryClient.RecordSessionStart(ctx, r.currentAgent, sess.ID)
161161
}
162162

163+
a := r.team.Agent(r.currentAgent)
164+
model := a.Model()
165+
modelID := model.ID()
166+
167+
messages := sess.GetMessages(a)
163168
if sess.SendUserMessage {
164-
events <- UserMessage(sess.GetMessages(r.CurrentAgent())[len(sess.GetMessages(r.CurrentAgent()))-1].Content)
169+
events <- UserMessage(messages[len(messages)-1].Content)
165170
}
166171

167172
events <- StreamStarted()
168-
a := r.team.Agent(r.currentAgent)
169-
170-
model := a.Model()
171-
modelID := model.ID()
172173

173174
defer r.finalizeEventChannel(ctx, sess, events)
174175

@@ -226,7 +227,6 @@ func (r *runtime) RunStream(ctx context.Context, sess *session.Session) <-chan E
226227
return
227228
}
228229
slog.Debug("Starting conversation loop iteration", "agent", a.Name())
229-
messages := sess.GetMessages(a)
230230
slog.Debug("Retrieved messages for processing", "agent", a.Name(), "message_count", len(messages))
231231

232232
// Retry loop for getting agent tools with OAuth handling

pkg/session/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func New(opts ...Opt) *Session {
200200
func (s *Session) GetMessages(a *agent.Agent) []chat.Message {
201201
slog.Debug("Getting messages for agent", "agent", a.Name(), "session_id", s.ID)
202202

203-
messages := make([]chat.Message, 0)
203+
var messages []chat.Message
204204

205205
if a.HasSubAgents() {
206206
subAgents := append(a.SubAgents(), a.Parents()...)
@@ -213,7 +213,7 @@ func (s *Session) GetMessages(a *agent.Agent) []chat.Message {
213213
}
214214

215215
messages = append(messages, chat.Message{
216-
Role: "system",
216+
Role: chat.MessageRoleSystem,
217217
Content: "You are a multi-agent system, make sure to answer the user query in the most helpful way possible. You have access to these sub-agents:\n" + subAgentsStr + "\nIMPORTANT: You can ONLY transfer tasks to the agents listed above using their ID. The valid agent IDs are: " + strings.Join(validAgentIDs, ", ") + ". You MUST NOT attempt to transfer to any other agent IDs - doing so will cause system errors.\n\nIf you are the best to answer the question according to your description, you can answer it.\n\nIf another agent is better for answering the question according to its description, call `transfer_task` function to transfer the question to that agent using the agent's ID. When transferring, do not generate any text other than the function call.\n\n",
218218
})
219219
}

0 commit comments

Comments
 (0)