Supports json response format for OpenAI#1367
Conversation
PR Summary by QodoAdd configurable JSON response format support for OpenAI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. GetChatResponseFormat uses ToLower()
|
| return format?.ToLower() switch | ||
| { | ||
| "json" or "json_object" => ChatResponseFormat.CreateJsonObjectFormat(), | ||
| "text" => ChatResponseFormat.CreateTextFormat(), | ||
| _ => null | ||
| }; |
There was a problem hiding this comment.
1. getchatresponseformat uses tolower() 📘 Rule violation ≡ Correctness
The new response-format parsing normalizes with format?.ToLower(), which is culture-sensitive and can cause incorrect identifier matching in some locales. This violates the requirement to use ordinal, case-insensitive comparisons for identifier-like strings.
Agent Prompt
## Issue description
The response-format parsing currently normalizes `agent.LlmConfig?.ResponseFormat` using `format?.ToLower()` before switching/matching, which performs a culture-sensitive conversion and can lead to incorrect identifier matching in certain locales. Update this logic to use ordinal, case-insensitive comparisons suitable for identifier-like strings.
## Issue Context
This parsing logic interprets `agent.LlmConfig?.ResponseFormat` values such as `json` and `text`.
## Fix Focus Areas
- src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.Chat.cs[637-644]
- src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.Response.cs[593-601]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| public AgentLlmConfig(AgentTemplateConfig templateConfig) | ||
| { | ||
| Provider = templateLlmConfig.Provider; | ||
| Model = templateLlmConfig.Model; | ||
| MaxOutputTokens = templateLlmConfig.MaxOutputTokens; | ||
| ReasoningEffortLevel = templateLlmConfig.ReasoningEffortLevel; | ||
| Provider = templateConfig.LlmConfig?.Provider; | ||
| Model = templateConfig.LlmConfig?.Model; | ||
| MaxOutputTokens = templateConfig.LlmConfig?.MaxOutputTokens; | ||
| ReasoningEffortLevel = templateConfig.LlmConfig?.ReasoningEffortLevel; | ||
| ResponseFormat = templateConfig.ResponseFormat; |
There was a problem hiding this comment.
2. Template drops response_format 🐞 Bug ≡ Correctness
When a template has a valid LlmConfig, InstructService replaces the agent’s LlmConfig with new AgentLlmConfig(template), and the new constructor sets ResponseFormat only from template.ResponseFormat. If the template omits response_format but the agent-level LlmConfig.ResponseFormat is set (e.g., "json"), OpenAI requests won’t enable JSON mode for template-based executions.
Agent Prompt
## Issue description
Template-based LLM overrides currently replace the entire `AgentLlmConfig` and copy `ResponseFormat` only from the template. This causes agent-level `LlmConfig.ResponseFormat` (e.g., `json`) to be lost whenever the template has `LlmConfig.IsValid == true` but does not explicitly set `ResponseFormat`.
## Issue Context
- `InstructService.Execute` and `BuildInnerAgent` create a fresh `AgentLlmConfig` from the template when template `LlmConfig` is valid.
- OpenAI providers read `agent.LlmConfig.ResponseFormat` to set `ChatCompletionOptions.ResponseFormat` / `CreateResponseOptions.TextOptions.TextFormat`.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs[7-14]
- src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs[246-256]
- src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs[67-75]
## Implementation direction
Ensure `ResponseFormat` (and ideally other non-overridden LLM settings) fall back to the agent-level config when the template does not specify them. For example:
- Build `llmConfig` by cloning/starting from `agent.LlmConfig`, then override only the fields present in `template.LlmConfig` and `template.ResponseFormat`.
- Or update the constructor usage so that `ResponseFormat = template.ResponseFormat ?? agent.LlmConfig?.ResponseFormat` (requires passing the base config or doing the merge at the call site).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.