semantic-kernel
semantic-kernel copied to clipboard
.Net: Fix #13262: GeminiRequest to handle single turn requests correctly
Updated the CreateGeminiRequest to ensure that single turn requests end with a "user" role or no role
Motivation and Context
- The fix is required since Gemini API rejects single turn requests ending with "model" role, but orchestration passes agent responses directly to next agents.
- Fixes orchestration workflows with Gemini models that fail after the first agent with HTTP 400 error.
- It contributes to multi-agent orchestration workflows using Gemini models.
- Fixes: https://github.com/microsoft/semantic-kernel/issues/13262
Description
Removes role from single assistant messages in Gemini requests (Gemini treats no role as user input). Only affects Gemini connector, preserves multi-turn conversations, no breaking changes. Basically this is a specific case solution to keep Gemini API satisfied.
Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone :smile:
@icyca this PR is still a draft, are you still working on it?
@markwallace-microsoft No, it is done. I just had it as draft in case it needed further discussion. I will publish it now
@markwallace-microsoft added unit tests