fix: convert tool result content to string for provider compatibility - #680
fix: convert tool result content to string for provider compatibility#680Giggitycountless wants to merge 1 commit into
Conversation
OpenAI's API accepts both string and list formats for tool message content, but third-party providers (DeepSeek, etc.) only accept a plain string, causing deserialization errors like: 'messages[N]: invalid type: sequence, expected a string' Add _tool_result_to_string() helper that extracts text from MCP content parts and joins them. This replaces the list-based content in execute_tool_call() with a provider-compatible string. Fixes lastmile-ai#25
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughTool-call message construction in OpenAI augmented LLM now converts MCP result content to a plain string instead of a list. A new helper method processes TextContent, ImageContent, and EmbeddedResource parts, concatenating text and inserting placeholders for non-text items. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
Description
OpenAI's API accepts both
stringandlist[ChatCompletionContentPartTextParam]formats for tool message content, but third-party providers (DeepSeek, etc.) only accept a plain string. This causes deserialization errors:Root Cause
In
execute_tool_call(), tool result content was built as a list:This creates
[{"type": "text", "text": "..."}]which OpenAI accepts but DeepSeek rejects.Fix
Add
_tool_result_to_string()helper that extracts text from MCP content parts and joins them into a plain string. For non-text parts (images, binary resources), includes a descriptive placeholder.The helper handles all MCP content types:
TextContent→ extracts.textEmbeddedResourcewithTextResourceContents→ extracts.resource.textEmbeddedResourcewithBlobResourceContents→[mimeType]placeholderImageContent→[image: mimeType]placeholderFixes #25
How Has This Been Tested?
_tool_result_to_string()correctly handles text, image, and empty contentgenerate_streamabstract method error is unrelated)Checklist
Summary by CodeRabbit
Release Notes