@@ -349,9 +349,8 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*ai.Agen
349 return result, err
349 return result, err
351 toolCalls := currentAssistant.ToolCalls()
351 toolCalls := currentAssistant.ToolCalls()
352− toolResults := currentAssistant.ToolResults()
353 // INFO: we use the parent context here because the genCtx has been cancelled
352 // INFO: we use the parent context here because the genCtx has been cancelled
354− msgs, createErr := a.messages.List(ctx, currentSession.ID)
353+ msgs, createErr := a.messages.List(ctx, currentAssistant.SessionID)
355 if createErr != nil {
354 if createErr != nil {
356 return nil, createErr
355 return nil, createErr
@@ -359,13 +358,13 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*ai.Agen
359 if !tc.Finished {
358 if !tc.Finished {
360 tc.Finished = true
359 tc.Finished = true
361 tc.Input = "{}"
360 tc.Input = "{}"
361+ currentAssistant.AddToolCall(tc)
363− currentAssistant.AddToolCall(tc)
365 found := false
364 found := false
366 for _, msg := range msgs {
365 for _, msg := range msgs {
367 if msg.Role == message.Tool {
366 if msg.Role == message.Tool {
368− for _, tr := range toolResults {
367+ for _, tr := range msg.ToolResults() {
369 if tr.ToolCallID == tc.ID {
368 if tr.ToolCallID == tc.ID {
370 found = true
369 found = true