Skip to content

preloadmemorytool skips memory search when text follows an image #1851

Open

Description

@ktsoator

Describe the Bug:
preloadmemorytool builds its search query from UserContent().Parts[0].Text only. If an image comes before the text, memory search is skipped. If the message contains multiple text parts, only the first is used.

Steps to Reproduce:

Save the code below as /tmp/preload-memory-repro.go and run it from the ADK Go repository root:

go run -mod=readonly /tmp/preload-memory-repro.go

Expected Behavior:
Join all non-empty text parts with spaces and use the result as the search query. Skip the search only when there is no text.

Observed Behavior:

text only: calls=1 query="my preferences" err=<nil>
image then text: calls=0 query="" err=<nil>
two text parts: calls=1 query="my" err=<nil>

Environment Details:

  • ADK Library Version: main at commit 72e40cdee98c00ca8b5c14243d84c0f3b6e13a59
  • OS: macOS (arm64)
  • Go Version: 1.26.6

Model Information:
N/A

Additional Context

ADK Python joins all non-empty text parts, while ADK Go only uses the first part.

Minimal Reproduction Code:

package main

import (
	"context"
	"fmt"

	"google.golang.org/adk/v2/agent"
	"google.golang.org/adk/v2/memory"
	"google.golang.org/adk/v2/model"
	"google.golang.org/adk/v2/tool/preloadmemorytool"
	"google.golang.org/genai"
)

type probeContext struct {
	agent.ContextMock
	content *genai.Content
	calls   int
	query   string
}

func (p *probeContext) UserContent() *genai.Content { return p.content }
func (p *probeContext) SearchMemory(_ context.Context, query string) (*memory.SearchResponse, error) {
	p.calls++
	p.query = query
	return &memory.SearchResponse{}, nil
}

func main() {
	for _, tc := range []struct {
		name  string
		parts []*genai.Part
	}{
		{"text only", []*genai.Part{{Text: "my preferences"}}},
		{"image then text", []*genai.Part{
			{FileData: &genai.FileData{MIMEType: "image/png", FileURI: "gs://example/image.png"}},
			{Text: "my preferences"},
		}},
		{"two text parts", []*genai.Part{{Text: "my"}, {Text: "preferences"}}},
	} {
		ctx := &probeContext{content: &genai.Content{Role: "user", Parts: tc.parts}}
		err := preloadmemorytool.New().ProcessRequest(ctx, &model.LLMRequest{})
		fmt.Printf("%s: calls=%d query=%q err=%v\n", tc.name, ctx.calls, ctx.query, err)
	}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions