Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Jul 3, 2025

PR Type

Bug fix


Description

  • Fix tool call ID handling in realtime providers

  • Replace empty function args with valid JSON object

  • Ensure consistent tool call ID fallback logic


Changes diagram

flowchart LR
  A["Tool Call Message"] --> B["Check Tool Call ID"]
  B --> C["Use Function Name as Fallback"]
  C --> D["Set Function Args to '{}'"]
  D --> E["Create Assistant & Tool Messages"]
Loading

Changes walkthrough 📝

Relevant files
Bug fix
ChatCompletionProvider.cs
Fix function arguments default value                                         

src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs

  • Replace empty function arguments with "{}" instead of empty string
+1/-1     
RealTimeCompletionProvider.cs
Fix tool call ID handling and arguments                                   

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs

  • Add tool call ID fallback using IfNullOrEmptyAs(message.FunctionName)
  • Replace empty function arguments with "{}" instead of empty string
  • Apply consistent ID handling to both assistant and tool messages
  • +2/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-merge-pro
    Copy link

    qodo-merge-pro bot commented Jul 3, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Consistency Issue

    The tool call ID fallback logic is applied to ChatToolCall creation but not to ToolChatMessage creation on line 276, creating inconsistency between the two providers and potentially causing ID mismatches.

        ChatToolCall.CreateFunctionToolCall(message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), message.FunctionName, BinaryData.FromString(message.FunctionArgs ?? "{}"))
    }));
    
    messages.Add(new ToolChatMessage(message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), message.Content));
    JSON Validation

    The fallback to empty JSON object "{}" for function arguments should be validated to ensure it doesn't break downstream JSON parsing or function execution logic that might expect specific argument structures.

        ChatToolCall.CreateFunctionToolCall(message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), message.FunctionName, BinaryData.FromString(message.FunctionArgs ?? "{}"))
    }));

    @qodo-merge-pro
    Copy link

    qodo-merge-pro bot commented Jul 3, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Validate JSON before serialization

    Validate that message.FunctionArgs contains valid JSON before passing to
    BinaryData.FromString(). Invalid JSON could cause runtime exceptions when the
    tool call is processed.

    src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs [273]

    -ChatToolCall.CreateFunctionToolCall(message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), message.FunctionName, BinaryData.FromString(message.FunctionArgs ?? "{}"))
    +ChatToolCall.CreateFunctionToolCall(message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), message.FunctionName, BinaryData.FromString(IsValidJson(message.FunctionArgs) ? message.FunctionArgs : "{}"))
    • Apply / Chat
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly points out that message.FunctionArgs could be a non-null but invalid JSON string, and validating it before use would make the code more robust against potential downstream errors.

    Medium
    • More

    @iceljc iceljc merged commit de34ac9 into SciSharp:master Jul 3, 2025
    4 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant