From 509c7a55b532804d6ab68c19b825cfc7cf3dc6b4 Mon Sep 17 00:00:00 2001 From: Yashraj Shukla Date: Thu, 13 Aug 2026 18:35:25 +0000 Subject: [PATCH] fix: extract content from function responses in session memory Previously, text from FunctionResponse parts was silently dropped when building session content for memory summarization, losing tool-call results from the summarized context. Marshal the response payload to JSON and include it, matching how text parts are already handled. Signed-off-by: Yashraj Shukla --- go/adk/pkg/memory/kagent_service.go | 7 +++++-- go/adk/pkg/memory/kagent_service_grpc_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/go/adk/pkg/memory/kagent_service.go b/go/adk/pkg/memory/kagent_service.go index b335851fd..b5f882a82 100644 --- a/go/adk/pkg/memory/kagent_service.go +++ b/go/adk/pkg/memory/kagent_service.go @@ -311,8 +311,11 @@ func (s *KagentMemoryService) extractSessionContent(session adksession.Session) // Get text content text := part.Text if text == "" && part.FunctionResponse != nil { - // TODO: Extract content from function response if needed - continue + responseJSON, err := json.Marshal(part.FunctionResponse.Response) + if err != nil || len(responseJSON) == 0 { + continue + } + text = fmt.Sprintf("[tool result from %s]: %s", part.FunctionResponse.Name, responseJSON) } if text != "" { diff --git a/go/adk/pkg/memory/kagent_service_grpc_test.go b/go/adk/pkg/memory/kagent_service_grpc_test.go index c3d312e59..f0ae4d7f1 100644 --- a/go/adk/pkg/memory/kagent_service_grpc_test.go +++ b/go/adk/pkg/memory/kagent_service_grpc_test.go @@ -268,6 +268,13 @@ func TestKagentMemoryServiceExtractSessionContent(t *testing.T) { name: "function call only", events: []*adksession.Event{newMockEventWithFunctionCall("agent", "get_weather")}, }, + { + name: "function response is extracted", + events: []*adksession.Event{ + newMockEventWithFunctionResponse("agent", "get_weather", map[string]any{"temperature": 72, "condition": "sunny"}), + }, + wantContent: `"condition":"sunny"`, + }, } for _, test := range tests { @@ -378,3 +385,14 @@ func newMockEventWithFunctionCall(author, functionName string) *adksession.Event event.Content = &genai.Content{Role: author, Parts: []*genai.Part{{FunctionCall: &genai.FunctionCall{Name: functionName}}}} return event } + +func newMockEventWithFunctionResponse(author, functionName string, response map[string]any) *adksession.Event { + event := newMockEvent(author, "") + event.Content = &genai.Content{ + Role: author, + Parts: []*genai.Part{{ + FunctionResponse: &genai.FunctionResponse{Name: functionName, Response: response}, + }}, + } + return event +}