Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Jan 14, 2026

PR Type

Bug fix


Description

  • Fix reasoning effort level fallback logic

  • Only use agent config when model matches current model

  • Prevent incorrect reasoning effort from being applied


Diagram Walkthrough

flowchart LR
  A["Get reasoning_effort_level from state"] --> B{"Is level empty AND<br/>model matches agent config?"}
  B -->|Yes| C["Use agent config<br/>ReasoningEffortLevel"]
  B -->|No| D["Use state value<br/>or null"]
  C --> E["Parse reasoning effort level"]
  D --> E
Loading

File Walkthrough

Relevant files
Bug fix
ChatCompletionProvider.cs
Add model matching check for reasoning effort fallback     

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

  • Changed reasoning effort level fallback logic from unconditional to
    conditional
  • Added model matching check before using agent config value
  • Only applies agent config reasoning effort when current model matches
    agent's configured model
+6/-2     

@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Compare model names case-insensitively

Perform a case-insensitive comparison for model names to prevent mismatches due
to casing differences.

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs [600]

-if (string.IsNullOrEmpty(level) && _model == agent?.LlmConfig?.Model)
+if (string.IsNullOrEmpty(level) && string.Equals(_model, agent?.LlmConfig?.Model, StringComparison.OrdinalIgnoreCase))
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This suggestion correctly points out that model names are often case-insensitive. Using a case-sensitive comparison could lead to the fallback logic not being applied due to simple casing differences, so this change improves the correctness of the logic.

Medium
Remove redundant null-conditional access

Improve code clarity and safety by adding an explicit null check for
agent?.LlmConfig and removing redundant null-conditional operators within the if
block.

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs [600-603]

-if (string.IsNullOrEmpty(level) && _model == agent?.LlmConfig?.Model)
+if (string.IsNullOrEmpty(level) && agent?.LlmConfig != null && _model == agent.LlmConfig.Model)
 {
-    level = agent?.LlmConfig?.ReasoningEffortLevel;
+    level = agent.LlmConfig.ReasoningEffortLevel;
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that the null-conditional access inside the if block can be improved. The proposed change with an explicit agent?.LlmConfig != null check makes the code more robust and readable by ensuring objects are not null before they are accessed.

Low
Treat whitespace-only state as empty

Replace string.IsNullOrEmpty with string.IsNullOrWhiteSpace to handle cases
where the level variable from the state contains only whitespace characters.

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs [600-603]

-if (string.IsNullOrEmpty(level) && _model == agent?.LlmConfig?.Model)
+if (string.IsNullOrWhiteSpace(level) && _model == agent?.LlmConfig?.Model)
 {
     level = agent?.LlmConfig?.ReasoningEffortLevel;
 }
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: This is a good suggestion for improving robustness. Using string.IsNullOrWhiteSpace handles edge cases where the state might contain a string with only whitespace, which should likely be treated as an empty value, thus correctly triggering the fallback logic.

Low
  • More

@iceljc iceljc merged commit 089c94f into SciSharp:master Jan 14, 2026
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