Skip to content

fix(adk): serialize nil FunctionCall.Args as {} not null for OpenAI adapters (#2851) - #2856

Closed
boxcee-interview wants to merge 1 commit into
kagent-dev:mainfrom
boxcee-interview:fix/issue-2851
Closed

boxcee-interview wants to merge 1 commit into
kagent-dev:mainfrom
boxcee-interview:fix/issue-2851

Conversation

@boxcee-interview

@boxcee-interview boxcee-interview commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Closes #2851

What was wrong

A zero-argument tool call succeeds in one task, then fails on the follow-up task after history is reloaded. Persistence drops empty function-call args (FunctionCall.Args is json:"args,omitempty"), so a reloaded call carries a nil Args map. The OpenAI chat-completions and Responses adapters then serialized that nil map as the string "null" instead of "{}". Object-validating backends (oMLX/ollama) reject it with HTTP 422.

What the fix does

Coerce a nil Args map to an empty map before marshaling, in the two OpenAI adapters that serialize function-call arguments:

  • go/adk/pkg/models/openai_adk.go (chat completions)
  • go/adk/pkg/models/openai_responses.go (Responses API)

This mirrors the identical nil-to-empty coercion already present in the Bedrock adapter (bedrock.go:686). Added two regression tests (one per adapter) asserting a nil-args call serializes to a JSON object, not null.

How to Test

Docker, golang:1.27, module root go/:

go test ./adk/pkg/models/ -run 'NilFunctionCallArgs' -v

Both tests PASS. Full package: go test ./adk/pkg/models/ → ok.

=== RUN   TestGenaiContentsToOpenAIMessages_NilFunctionCallArgs
--- PASS: TestGenaiContentsToOpenAIMessages_NilFunctionCallArgs (0.00s)
=== RUN   TestGenaiContentsToResponsesInput_NilFunctionCallArgs
--- PASS: TestGenaiContentsToResponsesInput_NilFunctionCallArgs (0.00s)

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 17, 2026
@supreme-gg-gg

Copy link
Copy Markdown
Contributor

This is a duplicate of #2852, pls check for existing PRs before opening a new one next time

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Zero-argument tool calls serialize as "null" after session reload in OpenAI-shaped adapters

2 participants