refine response format#1368
Conversation
PR Summary by QodoMove template response_format into LLM config and update persistence Description
Diagram
High-Level Assessment
Files changed (11)
|
Code Review by Qodo
1. Legacy response_format ignored
|
| { | ||
| public string Name { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Response format: json, xml, markdown, yaml, etc. | ||
| /// </summary> | ||
| [JsonPropertyName("response_format")] | ||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| public string? ResponseFormat { get; set; } | ||
|
|
||
| [JsonPropertyName("llm_config")] | ||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| public AgentTemplateLlmConfig? LlmConfig { get; set; } |
There was a problem hiding this comment.
1. Legacy response_format ignored 🐞 Bug ☼ Reliability
Existing stored templates that still use the old top-level response_format field will deserialize without that value (field removed), so the runtime AgentLlmConfig.ResponseFormat will not be set from legacy data. This silently changes LLM request behavior (e.g., OpenAI chat options.ResponseFormat becomes null) after upgrade.
Agent Prompt
### Issue description
`response_format` was removed from `AgentTemplateConfig` (and from Mongo template element), but repositories still load stored template configs/documents that may contain legacy top-level `response_format`. System.Text.Json and Mongo conventions will ignore unknown fields, so existing agents/templates silently lose this setting and runtime LLM calls won’t apply the intended response format.
### Issue Context
- Old schema: `[{ name, response_format, llm_config: {...} }]`
- New schema: `[{ name, llm_config: { ..., response_format } }]`
- Current load paths deserialize into `AgentTemplateConfig` and only apply `LlmConfig`, so legacy `response_format` is dropped.
### Fix Focus Areas
- src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentTemplate.cs[23-33]
- src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs[511-522]
- src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs[5-30]
### Suggested approach
1. **File repository backward-compat**:
- Re-introduce a deprecated/legacy `ResponseFormat` property on `AgentTemplateConfig` *only for deserialization* (e.g., `[JsonPropertyName("response_format")]` + `[Obsolete]`).
- In `GetAgentTemplateConfigs`, after deserialization, migrate:
- If `config.ResponseFormat` is not null/empty and `config.LlmConfig?.ResponseFormat` is null/empty, set `config.LlmConfig ??= new AgentTemplateLlmConfig(); config.LlmConfig.ResponseFormat = config.ResponseFormat;`
- Optionally set `config.ResponseFormat = null` to avoid re-writing legacy field.
2. **Mongo backward-compat**:
- Re-introduce a deprecated `ResponseFormat` field on `AgentTemplateMongoElement` to read existing documents.
- In `ToDomainElement`, if `mongoTemplate.ResponseFormat` is set and `mongoTemplate.LlmConfig?.ResponseFormat` is null, migrate into the domain `LlmConfig.ResponseFormat`.
- Ensure `ToMongoElement` does **not** populate the legacy field (keep writing only the new nested format).
3. Add a small regression test (or fixture) covering deserialization of old template config JSON / Mongo element with top-level `response_format` and verifying it ends up in `template.LlmConfig.ResponseFormat`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.