Skip to content

fix: use []any instead of []string in loadartifactstool to fix structpb serialization#670

Open
brucearctor wants to merge 1 commit intogoogle:mainfrom
brucearctor:fix/loadartifactstool-structpb-slice-type
Open

fix: use []any instead of []string in loadartifactstool to fix structpb serialization#670
brucearctor wants to merge 1 commit intogoogle:mainfrom
brucearctor:fix/loadartifactstool-structpb-slice-type

Conversation

@brucearctor
Copy link
Copy Markdown

Description

Fixes #668

loadartifactstool.Run returns []string in its response map, which causes structpb.NewStruct to fail when the Vertex AI session service persists the function response event. structpb only supports []any, not typed slices like []string.

Changes

tool/loadartifactstool/load_artifacts_tool.go

  1. Run(): Convert []string to []any before returning in the result map, ensuring compatibility with structpb.NewStruct.

  2. processLoadArtifactsFunctionCall(): Replace the hard []string type assertion with a type switch that handles both []string (direct call) and []any (after a structpb round-trip where []string becomes []interface{}).

tool/loadartifactstool/load_artifacts_tool_test.go

  • Updated existing test expectations from []string to []any to match the new return type.
  • Added TestLoadArtifactsTool_Run_StructpbCompatibility: verifies that Run() output can be serialized via structpb.NewStruct (the core bug assertion).
  • Added TestLoadArtifactsTool_ProcessRequest_Artifacts_LoadArtifactsFunctionCall_AnySlice: verifies ProcessRequest handles []any in the function response (simulating a round-trip).

Testing Plan

Unit Tests

go test ./tool/loadartifactstool/ -v -count=1

All 13 tests pass:

  • 8 existing Run tests (updated expectations)
  • 1 new StructpbCompatibility test
  • 2 existing ProcessRequest tests
  • 1 new ProcessRequest_AnySlice test
  • 1 existing OtherFunctionCall test

Minimal Reproduction (from issue)

result := map[string]any{"artifact_names": []string{"a.pdf", "b.pdf"}}
_, err := structpb.NewStruct(result) // BEFORE: proto: invalid type: []string

// After fix, Run() returns []any:
result = map[string]any{"artifact_names": []any{"a.pdf", "b.pdf"}}
_, err = structpb.NewStruct(result)  // AFTER: <nil>

…pb serialization

loadartifactstool.Run returned []string in its response map, which
caused structpb.NewStruct to fail when persisting the function response
event to the Vertex AI session service.

- Convert []string to []any in Run() before returning the result map
- Handle both []string and []any in processLoadArtifactsFunctionCall()
  to support values after a structpb round-trip (where []string becomes
  []interface{})
- Update test expectations and add structpb compatibility test
- Add test for []any function response handling

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loadartifactstool breaks Vertex AI session persistence due to []string in function response

1 participant