Skip to content

Preserve sibling tool calls in assistant imports#336

Draft
colinbennettbrain wants to merge 3 commits into
mainfrom
colin-spans-reasoning
Draft

Preserve sibling tool calls in assistant imports#336
colinbennettbrain wants to merge 3 commits into
mainfrom
colin-spans-reasoning

Conversation

@colinbennettbrain

Copy link
Copy Markdown

Summary

Fixes Lingua import handling for assistant role messages that contain Anthropic-style content[].type = "thinking" blocks alongside sibling OpenAI-style tool_calls.

The importer now parses this mixed assistant shape at a typed compatibility boundary and preserves both the reasoning content and sibling tool calls in the resulting universal assistant message.

It also avoids preempting OpenAI/OpenRouter/vLLM-style messages with top-level reasoning or reasoning_signature, allowing the existing OpenAI provider parser to preserve those fields.

Root cause

try_parse_mixed_role_messages_for_import offered role-message items to provider parsers before the lenient fallback. A provider parser could preserve content[].thinking while ignoring sibling tool_calls. The lenient assistant fallback only parsed content, so sibling tool calls were invisible there too.

Tests

  • CASE_FILTER=role-message-thinking-with-sibling-tool-calls cargo +1.95.0 test -p lingua --test import_fixtures -- --nocapture
  • CASE_FILTER=role-message-openai-reasoning-with-sibling-tool-calls cargo +1.95.0 test -p lingua --test import_fixtures -- --nocapture
  • cargo +1.95.0 test -p lingua --test import_fixtures -- --nocapture
  • RUSTUP_TOOLCHAIN=1.95.0 make typed-boundary-check

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.

1 participant