Skip to content

fix(adk): guard nil tool-call args and coerce to empty object in OpenAI-compatible adapters - #2852

Open
alexdarbyshire wants to merge 4 commits into
kagent-dev:mainfrom
alexdarbyshire:fix/nil-tool-call-arguments
Open

alexdarbyshire wants to merge 4 commits into
kagent-dev:mainfrom
alexdarbyshire:fix/nil-tool-call-arguments

Conversation

@alexdarbyshire

@alexdarbyshire alexdarbyshire commented Sep 17, 2026

Copy link
Copy Markdown

Issue

  • Nil tool-call args serialize as "null"
  • Occurs after session reload where reloaded session contains tool calls with no args (omitempty in upstream go-genai drops an empty map)
  • oMLX returns a 422, ollama returns a 400 to unexpected "null" string

Fixes #2851

Fix

  • Add nil guard clauses to OpenAI compatible adapters, coerce to empty object

Tests

  • Add regression test for each adapter

Notes

  • Considered abstracting in accordance with STYLE.md. Went with in-line guard for readability
  • AI used to write/wrangle code

SAP AI

  • added defensively for OpenAI compatibility (they support BYO Model)
  • Untested if SAP AI model proxy coerces "null" string to {} as several other providers do

References

note - defensive. SAP AI allows BYO model, I have not verified whether their LLM proxy will autofix or 422/500 "null" string

Signed-off-by: alexdarbyshire <[email protected]>
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 17, 2026
@alexdarbyshire alexdarbyshire changed the title fix(adk): guard nil tool-call args on replay in OpenAI-compatible adapters fix(adk): guard nil tool-call args and coerce to empty object in OpenAI-compatible adapters Sep 17, 2026
@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
supreme-gg-gg previously approved these changes Sep 18, 2026
Comment thread go/adk/pkg/models/openai_adk.go Outdated
var toolResponseMessages []openai.ChatCompletionMessageParamUnion
for _, fc := range functionCalls {
argsJSON, _ := json.Marshal(fc.Args)
args := fc.Args

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you refactor this to a shared until in models/base.go since this is used across openai, openai responses, sapaicore, and bedrock

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Extracted nonNilFunctionCallArgs into models/base.go and updated the four callers in 0efab2f6 :)

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.

2 participants