Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions internal/llminternal/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package llminternal

import (
"time"

"google.golang.org/genai"

"google.golang.org/adk/agent"
Expand Down Expand Up @@ -78,18 +76,15 @@ func generateRequestConfirmationEvent(
return nil
}

return &session.Event{
InvocationID: invocationContext.InvocationID(),
Author: invocationContext.Agent().Name(),
Branch: invocationContext.Branch(),
LLMResponse: model.LLMResponse{
Content: &genai.Content{
Parts: parts,
Role: genai.RoleModel,
},
event := session.NewEvent(invocationContext.InvocationID())
event.Author = invocationContext.Agent().Name()
event.Branch = invocationContext.Branch()
event.LLMResponse = model.LLMResponse{
Content: &genai.Content{
Parts: parts,
Role: genai.RoleModel,
},
Timestamp: time.Now(),
LongRunningToolIDs: longRunningToolIDs,
Actions: session.EventActions{},
}
Comment on lines +82 to 87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since session.Event embeds model.LLMResponse, you can set the Content field directly on the event object. This avoids the explicit model.LLMResponse struct literal, making the code a little more direct.

For example:

event.Content = &genai.Content{
    Parts: parts,
    Role:  genai.RoleModel,
}

This is functionally equivalent to the current implementation because session.NewEvent already zero-initializes the embedded model.LLMResponse struct.

event.LongRunningToolIDs = longRunningToolIDs
return event
}
7 changes: 7 additions & 0 deletions internal/llminternal/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestGenerateRequestConfirmationEvent(t *testing.T) {
InvocationID: "inv_1",
Author: "agent_1",
Branch: "main",
Actions: session.EventActions{StateDelta: map[string]any{}},
LLMResponse: model.LLMResponse{
Content: &genai.Content{
Role: genai.RoleModel,
Expand Down Expand Up @@ -180,6 +181,12 @@ func TestGenerateRequestConfirmationEvent(t *testing.T) {
}

if got != nil {
if got.ID == "" {
t.Errorf("expected event ID to be set, got empty string")
}
if got.Timestamp.IsZero() {
t.Errorf("expected event Timestamp to be set, got zero value")
}
for _, s := range got.LongRunningToolIDs {
if s == "" {
t.Errorf("empty long running tool id")
Expand Down