Skip to content

fix(session/vertexai): preserve FunctionCall and FunctionResponse IDs in deserialization#739

Open
nuthalapativarun wants to merge 3 commits intogoogle:mainfrom
nuthalapativarun:fix/679-vertexai-functioncall-id
Open

fix(session/vertexai): preserve FunctionCall and FunctionResponse IDs in deserialization#739
nuthalapativarun wants to merge 3 commits intogoogle:mainfrom
nuthalapativarun:fix/679-vertexai-functioncall-id

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Link to Issue or Description of Change

Description

aiplatformToGenaiContent was not populating the ID field when converting aiplatformpb.FunctionCall and aiplatformpb.FunctionResponse to their genai equivalents. The write path (createAiplatformpbContent) correctly serialized the ID, but it was silently dropped on read.

Root cause: In session/vertexai/vertexai_client.go, the struct literals for genai.FunctionCall and genai.FunctionResponse in aiplatformToGenaiContent were missing the ID field:

// Before (missing ID):
part.FunctionCall = &genai.FunctionCall{
    Name: v.FunctionCall.Name,
    Args: argsMap,
}

// After:
part.FunctionCall = &genai.FunctionCall{
    ID:   v.FunctionCall.Id,
    Name: v.FunctionCall.Name,
    Args: argsMap,
}

Impact: rearrangeEventsForFunctionResponsesInHistory uses the ID field to match function calls with their responses. With all IDs being empty strings, it mapped every call and response to the same "" key, silently keeping only the last function response and dropping all others from req.Contents in cross-invocation sessions.

Testing Plan

Unit Tests:

  • Added TestAiplatformToGenaiContent_PreservesFunctionCallAndResponseIDs in session/vertexai/vertexai_test.go verifying that the ID field is correctly preserved for both FunctionCall and FunctionResponse parts after deserialization.
  • All unit tests pass locally.
$ go test ./session/vertexai/...
ok  	google.golang.org/adk/session/vertexai	34.766s

Manual E2E Tests:

The bug is deterministic and fully covered by the unit test. Any multi-invocation session with tool calls would previously drop all but the last function response from history; after this fix the IDs are preserved and matching works correctly.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

… in deserialization

aiplatformToGenaiContent was not populating the ID field when converting
aiplatformpb.FunctionCall and aiplatformpb.FunctionResponse to their
genai equivalents. The write path (createAiplatformpbContent) correctly
serialized the ID, but it was lost on read.

This caused rearrangeEventsForFunctionResponsesInHistory to map all
function calls and responses to the empty string key, silently dropping
all but the last function response event in multi-invocation sessions.

Fixes google#679
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the conversion logic in vertexai_client.go to include the ID field for FunctionCall and FunctionResponse parts. A new test case was added to verify this mapping. The reviewer suggested refactoring the test into a table-driven format to match the existing codebase style and expanding it to cover additional fields.

Comment thread session/vertexai/vertexai_test.go Outdated
…verage

Refactor TestAiplatformToGenaiContent into a table-driven test to match
the style of other tests in this file. Also verify that Name, Args, and
Response fields are correctly preserved alongside ID during conversion.
@indurireddy-TF
Copy link
Copy Markdown
Contributor

Hi @nuthalapativarun The branch is currently out of date. Could you please update it ?

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

Projects

None yet

2 participants