AG2 & OpenAI Responses API: Seamless Migration Guide
Migration: Make AG2 Primary and Fully Supported with OpenAI Responses API (without breaking existing apps)
Why
The OpenAI Responses API is rapidly becoming the go-to interface, effectively building upon the classic Chat Completions with integrated tools like web search, file access, computer usage, structured state management, and real-time event streaming. It’s a significant upgrade, guys!
AG2 already plays well with OpenAI through LLMConfig(api_type=...)
, and while Responses is supported, it’s currently somewhat limited, primarily focusing on two-agent interactions initiated via initiate_chat
. To truly unlock the potential, we need to expand this support to cover all aspects without disrupting existing applications that rely on api_type="openai"
. Our goal is full AG2 feature parity with api_type="responses"
, which means ensuring seamless functionality across two-agent setups, GroupChat, tool and function calling, streaming capabilities, and multimodal interactions. And yes, we want to achieve this without breaking your current api_type="openai"
setups. It’s all about making the transition smooth and beneficial for everyone involved. Think of it as giving AG2 a super boost! We're talking about leveling up the whole experience by integrating these advanced capabilities while keeping everything else running smoothly. This means you get the best of both worlds: cutting-edge features and the reliability you've come to expect from AG2. So, get ready to see AG2 reach its full potential with the OpenAI Responses API, making your interactions smarter, more efficient, and more powerful than ever before!
To understand the scope of this enhancement, let's break down the core components we're aiming to integrate. First off, the built-in tools offered by the Responses API are a game-changer. Imagine having web search, file access, and even computer usage capabilities directly within your AI interactions. This eliminates the need for complex workarounds and allows for more seamless and natural conversations. The structured state management is another key feature. By maintaining a clear state throughout the conversation, AG2 can better understand context and provide more relevant responses. No more repeating yourself or losing track of the discussion! Finally, the event-streaming capability brings real-time updates and dynamic interactions to the table. This means you can see responses as they're generated, making the whole process feel more interactive and engaging. So, buckle up, guys, because AG2 is about to get a whole lot smarter and more powerful with the OpenAI Responses API.
Outcomes
Ultimately, we're aiming for several key outcomes here. Firstly, full AG2 feature parity with api_type="responses"
is crucial. This means ensuring that every feature available in AG2 works seamlessly with the Responses API. Think two-agent conversations, robust GroupChat functionalities, versatile tool and function calling, real-time streaming, and even multimodal interactions – we want it all! Secondly, and perhaps most importantly, we want no application-layer breaks. For those already using api_type="openai"
(Chat Completions), everything should continue to function as expected. The transition to Responses should be a smooth, config-only opt-in experience, minimizing any disruption to existing workflows. Lastly, we envision a thin compatibility/normalization layer. This layer will essentially translate Responses outputs into a format that AG2 can easily understand, ensuring a seamless integration with the existing codebase. It's like having a universal translator for your AI interactions!
The goal here is to make the migration to the OpenAI Responses API as seamless and painless as possible. We want you to be able to take advantage of all the new features and capabilities without having to rewrite your entire application. That's why the config-only opt-in is so important. It allows you to switch to the Responses API whenever you're ready, without affecting your existing setup. And the compatibility/normalization layer ensures that the new API works seamlessly with the old, so you don't have to worry about compatibility issues. We're also focusing on making sure that all the features you love about AG2, like GroupChat and multimodal interactions, continue to work flawlessly with the new API. So, rest assured, guys, we're doing everything we can to make this transition a smooth and successful one!
Backward-Compatibility Principles (Application-Layer Safety)
To ensure a smooth transition and maintain the integrity of existing applications, we're adhering to several key backward-compatibility principles. These principles are designed to minimize disruption and ensure that the migration to the Responses API is a seamless experience for everyone involved.
-
Config-Only Opt-In: The first and perhaps most crucial principle is the config-only opt-in approach. Users will be able to switch to the Responses API simply by setting
LLMConfig(api_type="responses")
. This means that the semantics ofapi_type="openai"
will remain untouched, ensuring that existing applications continue to function as expected. It’s all about providing a safe and controlled way to explore the new features without risking your current setup. We're essentially creating a parallel pathway, allowing you to experiment with the Responses API at your own pace and comfort level. This approach aligns with OpenAI's migration guidance and ensures that you have full control over when and how you transition to the new API. -
Normalize Outputs: To ensure compatibility with existing AG2 components, we're implementing a normalization layer. This layer will adapt Responses events into a ChatCompletion-shaped format. Many parts of AG2, as well as custom model clients, expect messages in this format (e.g.,
choices[0].message.content
,function_call
). By providing an internal adapter that maps Responses events to a Chat-like structure, we can ensure that agents consume information seamlessly. This normalization process is crucial for maintaining the stability and functionality of your applications. It's like having a translator that ensures everyone speaks the same language, regardless of the underlying API. This approach minimizes the need for code changes and allows you to leverage the new API without disrupting existing workflows. -
Dual Tool Path: We're implementing a dual tool path to provide flexibility and ensure compatibility with both existing AG2 tools and the built-in tools offered by the Responses API. In Chat mode, AG2 will continue to handle function/tool calls as it does today. However, in Responses mode, we'll allow the use of built-in tools when enabled (web/file/computer use), while also providing a fallback to AG2 tools for custom or unsupported functionalities. This hybrid approach gives you the best of both worlds, allowing you to leverage the power of the Responses API's built-in tools while still maintaining access to your custom tools. It's like having a toolbox with both standard and specialized tools, ensuring you're always equipped for the task at hand. This approach also allows for a gradual transition to the Responses API's tooling ecosystem, giving you time to adapt and integrate new tools as needed.
-
No Orchestration API Changes: To maintain stability and minimize disruption, we're committed to keeping the core orchestration APIs (
ConversableAgent
,AssistantAgent
,UserProxyAgent
, GroupChat) stable. Adaptation will occur beneath the surface, within the provider and message plumbing. This means you won't have to rewrite your existing orchestration logic to take advantage of the Responses API. It's like upgrading the engine of a car without changing the dashboard – the core functionality remains the same, but the performance is significantly enhanced. This approach ensures that your existing workflows and processes remain intact, while still allowing you to benefit from the new API's capabilities.
Phase 0 — Discovery & Audit (No Behavior Changes)
Goal: Enumerate where Chat-specific assumptions live and wire a minimal provider switch path.
In this initial phase, our primary goal is to identify all areas within the codebase that make specific assumptions about the Chat Completions API. This involves a comprehensive audit to understand how the existing system interacts with the OpenAI API and where adjustments might be needed to accommodate the Responses API. We also aim to establish a basic framework for switching between the Chat Completions and Responses APIs, ensuring a smooth transition in later phases. Think of this as the groundwork phase, where we're laying the foundation for a successful migration. We're not making any changes to the behavior of the system just yet, but we're gathering the information we need to make those changes effectively in the future.
This phase is all about discovery and planning. We're essentially mapping out the terrain before we start building. This includes identifying all the touchpoints within the code and documentation that are relevant to the API integration. By understanding these touchpoints, we can develop a clear strategy for migrating to the Responses API while minimizing disruption to existing functionality. This meticulous approach is crucial for ensuring a smooth and successful transition, allowing us to take full advantage of the new API's capabilities without breaking anything along the way. So, get ready for some serious detective work, guys, as we dive deep into the codebase to uncover all the secrets it holds!
Touchpoints (code & docs)
-
Provider selection & config
-
autogen/llm_config.py
(or equivalent): Honorsapi_type
to select OpenAI client flavor. This is where we'll be focusing on how AG2 selects the appropriate OpenAI client based on theapi_type
configuration. We need to ensure that the Responses API can be selected as an alternative to the Chat Completions API. It's like having a switch that lets you choose between different engines for your AI interactions. -
OpenAI client wrapper (linked in API nav as OpenAIWrapper): Ensure a Responses path exists and is usable via config. The OpenAI client wrapper acts as an intermediary between AG2 and the OpenAI API. We need to make sure that it includes a path for the Responses API and that this path can be activated through configuration. It's like having a translator that can speak both the language of AG2 and the language of the OpenAI API.
-
Config helpers:
config_list_openai_aoai(...)
andconfig_list_from_models(...)
are widely used—don’t break signatures/behavior. These configuration helpers are essential for setting up and managing OpenAI API connections. We need to ensure that their signatures and behavior remain consistent, even with the introduction of the Responses API. It's like making sure the steering wheel still works the same way, even after you've upgraded the engine.
-
-
Places that assume Chat-shape
-
Any parsing that expects
choices[*].message.content
/function_call
or token-stream deltas. This is a critical area of focus. We need to identify all places in the code where we're parsing responses from the Chat Completions API and adapt them to work with the Responses API's format. This might involve creating a compatibility layer to translate between the two formats. It's like learning a new language and figuring out how to translate key phrases and concepts.
-
-
Public orchestration surfaces (must remain stable)
-
autogen/agentchat/conversable_agent.py
— ConversableAgent (base for almost everything). The ConversableAgent is a fundamental component of AG2, serving as the foundation for many other agents. We need to ensure that its public interface remains stable, even as we integrate the Responses API. It's like making sure the foundation of a building remains solid, even as you add new floors. -
autogen/agentchat/group/*
— GroupChat, GroupChatManager. GroupChat and GroupChatManager are key components for multi-agent interactions. Similar to ConversableAgent, we need to maintain the stability of their public interfaces. It's like ensuring that the communication system in a building works seamlessly, even as you add more people to the network.
-
Phase 1 — Core Implementation (Responses Parity Behind a Flag)
Goal: Make major flows work with api_type="responses"
while app code stays the same.
Phase 1 is where the real magic begins, guys! Our primary goal is to implement core functionality that allows AG2 to work seamlessly with the api_type="responses"
, all while ensuring that existing application code remains untouched. This means building the necessary infrastructure to support the Responses API without requiring developers to rewrite their applications. It's like giving AG2 a major upgrade under the hood while keeping the user interface exactly the same. This approach minimizes disruption and allows developers to gradually adopt the new API at their own pace. We're essentially creating a parallel universe where AG2 can interact with both the Chat Completions API and the Responses API, giving you the flexibility to choose the best option for your needs.
This phase is all about building the foundation for Responses API integration. We're focusing on implementing the core components that will enable AG2 to communicate with the new API, process its responses, and handle its unique features. This includes building adapters, routers, and other internal mechanisms that will bridge the gap between the Responses API and AG2's existing architecture. By focusing on these core components, we can ensure that AG2 is fully equipped to take advantage of the new API's capabilities. So, get ready to see some serious progress, guys, as we bring the Responses API to life within AG2!
New internal pieces
-
Responses → Chat normalization adapter
-
Input: Responses event stream (text deltas, tool events, final message).
-
Output: A ChatCompletion-like object (
choices[0].message.content
, optionalfunction_call
, usage fields). This is a crucial component. We need to create an adapter that can take the event stream from the Responses API and transform it into a format that AG2 can understand. This means converting the Responses API's event-driven structure into a ChatCompletion-like object, which AG2 currently expects. It's like having a translator that can convert between two different languages, ensuring that everyone understands each other.
-
-
Streaming router
-
Convert Responses’ event-driven streaming to the same callbacks/hooks used today for token streaming. The Responses API uses an event-driven streaming model, which is different from the token-based streaming that AG2 currently uses. We need to create a router that can convert the Responses API's event stream into the same callbacks and hooks that AG2 uses for token streaming. This ensures that streaming functionality works consistently across both APIs. It's like having a traffic controller that can direct different types of vehicles onto the same road, ensuring a smooth flow of traffic.
-
Tooling integration
-
LLMConfig
withapi_type="responses"
+built_in_tools=[...]
: When present, pass through built-ins; otherwise route to AG2 tools. This configuration will allow us to specify which tools should be used with the Responses API. If built-in tools are enabled, we'll use them; otherwise, we'll fall back to AG2's existing tools. This provides flexibility and allows developers to choose the best tools for their specific needs. It's like having a toolbox with both standard and specialized tools, allowing you to choose the right tool for the job.
Group / multi-agent
-
Keep
GroupChat
/GroupChatManager
public usage the same. Internally maintain a single conversation state. We need to ensure that GroupChat and GroupChatManager continue to function as expected with the Responses API. This means maintaining a single conversation state internally, even though the underlying API is different. It's like having a team that can communicate effectively, even if they're using different communication channels.
Multimodal
-
Validate adapter with existing two-agent Responses examples (image/JSON output) and extend to GroupChat. Multimodal interactions, such as those involving images and JSON output, are an important aspect of the Responses API. We need to validate our adapter with existing examples and ensure that it works seamlessly with GroupChat. It's like ensuring that a communication system can handle different types of messages, including text, images, and data.
Sanity tests (must pass with both api_type
s)
- ConversableAgent ↔ ConversableAgent (2-agent chat).
- AssistantAgent + UserProxyAgent (code exec flows).
- GroupChat (round-robin/auto).
- Function/tool calling (AG2 tools + built-ins in Responses).
- Structured outputs & multimodal (image I/O).
To ensure the stability and functionality of AG2, we'll be conducting a series of sanity tests. These tests will cover a wide range of scenarios and ensure that AG2 works as expected with both the Chat Completions API and the Responses API. It's like putting a new car through a series of tests to ensure that it performs well in different conditions.
Phase 2 — Optimization & Feedback (Still No Breaking Changes)
Goal: Performance, UX, docs.
In Phase 2, our focus shifts towards optimization and gathering feedback, all while maintaining our commitment to no breaking changes. This means we'll be fine-tuning the integration of the Responses API to maximize performance and enhance the user experience. We'll also be actively seeking feedback from the community to identify areas for improvement. It's like polishing a gem, guys – we've got the core functionality in place, and now we're focusing on making it shine!
This phase is all about refinement and improvement. We'll be looking at everything from the speed and efficiency of the API integration to the clarity and usability of the documentation. Our goal is to create a seamless and enjoyable experience for developers using the Responses API with AG2. This includes optimizing the streaming of events, normalizing usage and cost tracking, and providing comprehensive documentation and examples. So, get ready to see some significant enhancements, guys, as we take the Responses API integration to the next level!
-
Event streaming polish: Present partial text like today’s token streaming; surface tool-progress logs when Responses invokes built-ins. We'll be focusing on making the event streaming experience as smooth and intuitive as possible. This includes presenting partial text in a way that's consistent with AG2's current token streaming and surfacing tool-progress logs when the Responses API invokes built-in tools. It's like making sure the information is presented in a clear and easy-to-understand format.
-
Usage/cost tracking: Normalize Responses usage into the same fields AG2 exposes today. We need to ensure that usage and cost tracking for the Responses API is consistent with AG2's existing tracking mechanisms. This means normalizing the data into the same fields that AG2 currently exposes. It's like having a unified accounting system that tracks all expenses in the same way.
-
Docs & examples: “Chat vs Responses” side-by-side. Clear and comprehensive documentation is crucial for the adoption of any new feature. We'll be providing side-by-side examples that demonstrate the differences between the Chat Completions API and the Responses API. It's like having a Rosetta Stone that helps you translate between two different languages.
Phase 3 — Transition & Compatibility Affordances
Goal: Make Responses the recommended default while preserving legacy mode.
Phase 3 marks a significant step in our journey, guys, as we aim to make the Responses API the recommended default for AG2. However, we also recognize the importance of preserving the legacy Chat Completions mode for those who still rely on it. This phase is all about striking a balance between encouraging adoption of the new API and ensuring a smooth transition for existing users. It's like upgrading a highway system while keeping the old roads open for those who prefer them.
This phase is about setting the stage for the future. We'll be making changes to the default configurations and examples to promote the use of the Responses API. However, we'll also be providing clear guidance and support for those who need to continue using the Chat Completions API. This includes offering optional routing shims and other tools to help with the transition. So, get ready to embrace the future, guys, as we make the Responses API the new standard for AG2!
-
Default presets/examples use
api_type="responses"
; legacy examples under “Classic (Chat)”. We'll be updating the default presets and examples to use theapi_type="responses"
. However, we'll also be providing legacy examples under a “Classic (Chat)” section for those who need them. It's like providing both a modern and a classic version of a product, allowing users to choose the one that best suits their needs. -
Optional routing shim (opt-in env var): For simple cases, route legacy calls through Responses transparently. For simple use cases, we'll be providing an optional routing shim that can transparently route legacy calls through the Responses API. This can help simplify the transition for some users. It's like having a translator that can automatically convert between two different languages, making communication seamless.
Phase 4 — Post-Migration Evolution (Internal Cleanup, Not User-Visible)
Goal: Simplify internals once adoption is broad.
Phase 4 is all about internal cleanup and simplification, guys. Once the Responses API has been widely adopted, we can start to streamline the internal workings of AG2. This phase focuses on removing redundant code and simplifying the architecture, making AG2 more efficient and maintainable. It's like decluttering your house after a big move – you've got everything in place, and now you can focus on making it more organized and efficient.
This phase is about long-term sustainability. We'll be focusing on making AG2 easier to maintain and extend in the future. This includes retiring double bookkeeping of conversation state and keeping the adapter for ecosystem compatibility. These changes will not be user-visible, but they will make AG2 a more robust and efficient platform. So, get ready for some behind-the-scenes magic, guys, as we make AG2 even better under the hood!
- Retire double bookkeeping of conversation state if the Responses path/adaptor is robust. If the Responses API integration proves to be robust, we can retire the double bookkeeping of conversation state, which will simplify the internal architecture.
- Keep the adapter long-term for ecosystem compatibility. We'll be keeping the adapter for the Responses API long-term to ensure compatibility with the broader ecosystem. This will make it easier for AG2 to integrate with other tools and services.