Fix groupchat responses api
Why are these changes needed?
This PR resolves a compatibility issue that caused GroupChat to fail when using OpenAI’s Responses API. Added streaming response support and proper ID handling for Responses API. It also improves validation and error handling for more reliable performance.
Related issue number
Closes: #2022
Checks
- [x] I've included any doc changes needed for https://docs.ag2.ai/. See https://docs.ag2.ai/latest/docs/contributor-guide/documentation/ to build and test documentation locally.
- [x] I've added tests corresponding to the changes introduced in this PR.
- [x] I've made sure all auto checks have passed.
Thanks for creating this @tejas-dharani.
I think we should avoid changing the speaker selection template prompt as I believe it can be changed through the API and changing the default will affect those already using it.
In conjunction with that, the speaker selection choosing the same agent again isn't a restriction that I think we should have as it may be very valid for an agent to be selected again (e.g. it has been determined that they have not finished their task).
@tejas-dharani Before diving into the implementation details, I would like to clarify a few things,
- Chat completion APIs&Clients is not just for OAI but also for all OAI compatible models, e.g. deepseek, Bedrock etc (basically except Gemini all other models are compatible to chat completion)
- Responsible API is OAI only for now.
- AG2 supports agent orchestration on top of different LLMs which means the change needs to be generic enough.
- When you dev, please use the notebook examples to verify if your changes actually works.
- Use groupchat to support responses api is not a trivial task. Could you write a one pager or use an issue to discuss before jump into coding?
@tejas-dharani Before diving into the implementation details, I would like to clarify a few things,
- Chat completion APIs&Clients is not just for OAI but also for all OAI compatible models, e.g. deepseek, Bedrock etc (basically except Gemini all other models are compatible to chat completion)
- Responsible API is OAI only for now.
- AG2 supports agent orchestration on top of different LLMs which means the change needs to be generic enough.
- When you dev, please use the notebook examples to verify if your changes actually works.
- Use groupchat to support responses api is not a trivial task. Could you write a one pager or use an issue to discuss before jump into coding?
- I’ve already tested the changes extensively with my OpenAI API.
- This was already discussed in issue #2022.
Codecov Report
:x: Patch coverage is 55.68182% with 39 lines in your changes missing coverage. Please review.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| autogen/agentchat/groupchat.py | 67.78% <93.33%> (-3.51%) |
:arrow_down: |
| autogen/oai/client_utils.py | 81.92% <44.00%> (-12.90%) |
:arrow_down: |
| autogen/oai/openai_responses.py | 72.65% <50.00%> (+2.70%) |
:arrow_up: |
... and 40 files with indirect coverage changes
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@randombet do you have any further comments on this?