Skip to content

Fix OpenAI content encoding for thinking parts and empty arrays#428

Open
laudney wants to merge 1 commit intoagentjido:mainfrom
mmonad:fix/openai-thinking-content-encoding
Open

Fix OpenAI content encoding for thinking parts and empty arrays#428
laudney wants to merge 1 commit intoagentjido:mainfrom
mmonad:fix/openai-thinking-content-encoding

Conversation

@laudney
Copy link
Contributor

@laudney laudney commented Feb 16, 2026

Summary

  • Strip :thinking ContentParts in the OpenAI encoder — reasoning models (e.g. gpt-oss on vLLM) emit chain-of-thought thinking parts that have no OpenAI encoding. The catch-all returns nil, but an explicit clause makes intent clear.
  • Collapse empty content arrays to "" — when all parts are filtered (e.g. assistant message with only :thinking before tool calls), content: [] is rejected by vLLM's strict Pydantic validation. Now normalizes to "" instead.

Test plan

  • Tested with gpt-oss-12b on vLLM — multi-turn tool calling with thinking content now works
  • Tested with Qwen3-Coder on vLLM — no regression
  • Add unit test for :thinking content part encoding
  • Add unit test for empty content array normalization

@mikehostetler mikehostetler added the needs_work Changes requested before merge label Feb 16, 2026
@laudney
Copy link
Contributor Author

laudney commented Mar 2, 2026

Hey! I've added the missing unit tests that were flagged in the test plan:

  • :thinking content part encoding — verifies thinking parts are stripped and remaining text flattens correctly
  • Empty content array normalization — verifies content: [] collapses to "" (the vLLM/strict Pydantic fix)
  • Also updated the existing "encodes tool calls correctly" test expectation from content: [] to content: "" to align with the fix

All 32 tests in defaults_test.exs pass. Would appreciate another look when you get a chance — thanks!

@laudney laudney force-pushed the fix/openai-thinking-content-encoding branch from 1c85acd to b2dbe68 Compare March 2, 2026 11:21
@laudney
Copy link
Contributor Author

laudney commented Mar 2, 2026

Rebased onto upstream main — merge conflict resolved.

@laudney laudney force-pushed the fix/openai-thinking-content-encoding branch from b2dbe68 to 1813e02 Compare March 2, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs_work Changes requested before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants