Repository navigation
Conversation
A gpt-oss tool call's header carries a content type: ` <|constrain|>json` or a
bare ` code`. The renderer picked it from the arguments when re-rendering a
conversation from messages, but the model doesn't always match the two: it can
sample
<|channel|>commentary to=functions.bash code<|message|>{"command":"ls"}<|call|>
and a re-render of that call wrote
<|channel|>commentary to=functions.bash <|constrain|>json<|message|>{"command":"ls"}<|call|>
so the re-rendered history no longer matched the sampled tokens.
ParsedToolCall gains content_type, the parser sets it from the call's header
(the word after <|constrain|>, else the header's bare content type, None when
there is none), and the renderer uses a tool call's content_type when given
(json or code), falling back to the arguments' type as before.
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Will Brown <will@primeintellect.ai>
Co-authored-by: Cursor <cursoragent@cursor.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A gpt-oss tool call's header carries a content type:
<|constrain|>jsonor a barecode. When a conversation is re-rendered from messages, the renderer picks the content type from the arguments (jsonfor a JSON object,codeotherwise). The model doesn't always match the two. It can sampleand re-rendering that call from its message writes
so the re-rendered history no longer matches the tokens the model sampled.
The fix:
ParsedToolCallgainscontent_type. The gpt-oss parser sets it from the call's header: the word after<|constrain|>, else the header's bare content type, andNonewhen the header has none.content_typewhen it's given (jsonorcode, on the tool-call dict or itsfunctiondict). Otherwise it falls back to the arguments' type as before, so calls without it render unchanged.Tests: a
codecall on JSON arguments now round-trips token for token, and header parsing is covered for both header orders and for a header with no content type.This is stacked on
gpt-oss-tool-call-arguments-text, which addsarguments_textthe same way.Note
Low Risk
Scoped to gpt-oss Harmony parse/render round-trips; other renderers leave
content_typeunset and behavior unchanged when the field is omitted.Overview
gpt-oss tool-call headers can say
json(<|constrain|>json) orcode(barecode), but re-rendering from messages used to infer the type from the argument body only. When the model sampledcodefor a JSON object, the history no longer matched the original tokens.ParsedToolCall now carries optional
content_type, set by the gpt-oss parser from the header (word after<|constrain|>, otherwise the bare type after the recipient, including recipient-first layouts). The gpt-oss renderer honorscontent_typeon the tool-call orfunctiondict when it isjsonorcode, and otherwise keeps the old argument-based fallback.New tests cover
codeon JSON arguments round-tripping token-for-token and header parsing when the type is missing.Reviewed by Cursor Bugbot for commit b77bec7. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Preserve sampled gpt-oss tool-call content type on re-render
parse_gpt_ossin parsing.py now extracts the content-type word from tool-call headers and stores it onParsedToolCall, including for invalid-JSON calls. Other formats leave itNone.GptOssRendererreadscontent_typefrom the tool-call dict (or itsfunctiondict) and uses it when it isjsonorcode; otherwise it infers the type from the arguments as before.codeheader on JSON arguments was re-rendered asjson, producing different assistant tokens than what was sampled.ParsedToolCallgains an optionalcontent_typefield defaulting toNone; re-rendered gpt-oss headers can now usecodewhere they previously always usedjsonfor JSON arguments.Macroscope summarized b77bec7.