fix: extract content from function responses in session memory - #2437
fix: extract content from function responses in session memory#2437yashrajshuklaaa wants to merge 1 commit into
Conversation
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 <shuklayashraj68@gmail.com>
supreme-gg-gg
left a comment
There was a problem hiding this comment.
Function responses were initially skipped intentionally, since I wasn't sure if they belong in cross-session memory which is intended for things like knowledge distillation and learning.
Tool results like the weather API example you quoted are usually session-local. If they matter later, the model typically includes them in later events, which the session summary already captures. Dumping every function response will inflate the event list and make summarization harder, or flood memory with low-quality entries and dilute search quality.
This is why I left them out, but I'm open to adding this if you can make a case for it.
|
@supreme-gg-gg Fair concerns. On "the model restates it later" imo that's not reliable, when it acts on a result it usually just summarizes in its own words instead of repeating exact values (IDs, numbers), so those still get lost. |
What
Extracts text content from
FunctionResponseparts when building session content for memory summarization, instead of silently dropping them.Why
extractSessionContentinkagent_service.gobuilds a text summary of a session's events for memory storage. Previously, when a part had noTextbut did have aFunctionResponse(i.e. a tool call result), the content was skipped entirely via a// TODO: Extract content from function response if neededand acontinue. This meant tool outputs were invisible to sessionmemory summarization, only user/agent text made it in, even though tool results are often the most useful context to remember (e.g. "what did the weather API return").
Change
part.FunctionResponse.Response(amap[string]any) to JSON and include it in the extracted content, prefixed with[tool result from <function_name>]:so it's distinguishable from regular text in the summary.Testing
newMockEventWithFunctionResponsetest helper alongside the existingnewMockEventWithFunctionCall.TestKagentMemoryServiceExtractSessionContentcovering a function-response-only event and asserting its content is present in the output.gofmt -l, cleango vet ./adk/pkg/memory/..., cleango test -race ./adk/pkg/memory/..., passgolangci-lint run ./adk/pkg/memory/..., 0 issuesScope
Small, self-contained change to a single function in one package. No new dependencies, no API/behavior changes outside of
extractSessionContent.