Problem/Motivation

There's no official date, but based on the verbiage spattered throughout in the docs sounds like it eventually will just be replaced:

Starting a new project? We recommend trying Responses to take advantage of the latest OpenAI platform features. Compare Chat Completions with Responses.

And

While Chat Completions remains supported, Responses is recommended for all new projects.

This also appears to have some performance impacts:

Better performance: Using reasoning models, like GPT-5, with Responses will result in better model intelligence when compared to Chat Completions. Our internal evals reveal a 3% improvement in SWE-bench with same prompt and setup.

Proposed resolution

Look into the changes required by both the providers and the AI base classes to make this BC but also enable newer features.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

b_sharpe created an issue. See original summary.

efpapado’s picture

Assigned: Unassigned » efpapado

I started doing some work here. As a first approach, I'll copy the logic of the \Drupal\ai_provider_openai\Plugin\AiProvider\OpenAiProvider::chat + \Drupal\ai\OperationType\Chat\ChatInterface, to treat it as a different operation type, with its own AiApiExplorer plugin. I'm implementing the simplest possible request structure, and then it can be extended. I'm currently working on the 1.2.x branch.

efpapado’s picture

Assigned: efpapado » Unassigned
Status: Active » Needs review

Here is a first attempt. It is the simplest possible, not covering all the possible options.
It will be combined with another MR to the core AI module that will add a Responses Generator.
It includes also a Responses Generator plugin.

My thought was to just implement the communication to the Responses endpoint independently, as a separate operation type, while keep using the Chat as default. When the Responses is ready, we could decide on the next step, which could be either moving the default actions to Responses, or offer it as a configuration option.

arianraeesi’s picture

b_sharpe’s picture

Status: Needs review » Needs work

In speaking with Artem in standup, we both agreed it doesn't make sense to add this as a separate operator type, but rather just replace the chat completions.

No other providers have chat/responses, just chat, so the operation isn't changing, just the endpoint for OpenAI. So we should probably pivot this one to instead replace rather than append.

Also, chat completions will (eventually) just go away once OpenAI decides to fully deprecate it

ahmad-khalil-imagex’s picture

Assigned: Unassigned » ahmad-khalil-imagex
efpapado’s picture

@b_sharpe apart from the endpoint, isn't also the expected structure of the requests different?

b_sharpe’s picture

@efpapado, Yes, this will need a fairly large refactor (a newly forked MR is best). Chatting is primary focus as this should essentially be backwards compatible; however, it will also open the door to the new future features like:

  • Internal Tools (web search, file search, code interpreter, etc.)
  • Internal Memory (via either previous_response_id or conversations API)
  • Vector store integration
  • Native structured output support
  • etc

ahmad-khalil-imagex’s picture

Assigned: ahmad-khalil-imagex » Unassigned
Status: Needs work » Needs review
a.dmitriiev’s picture

I wonder, should we add "Stateful context" setting:

Use store: true to maintain state from turn to turn, preserving reasoning and tool context from turn-to-turn.

See the documentation https://developers.openai.com/api/docs/guides/migrate-to-responses#about...

a.dmitriiev’s picture

Status: Needs review » Needs work

Otherwise the MR looks good, but needs rebase.

ahmad-khalil-imagex’s picture

Assigned: Unassigned » ahmad-khalil-imagex
ahmad-khalil-imagex’s picture

Assigned: ahmad-khalil-imagex » Unassigned
ahmad-khalil-imagex’s picture

Status: Needs work » Needs review
a.dmitriiev’s picture

Status: Needs review » Needs work

I am really sorry @ahmad-khalil-imagex to not be specific last time, as it is a new feature, we need to target 1.3.x instead. Could you please rebase again?

ahmad-khalil-imagex’s picture

Assigned: Unassigned » ahmad-khalil-imagex

No worries @a.dimitriev Will rebase again now.

ahmad-khalil-imagex’s picture

Assigned: ahmad-khalil-imagex » Unassigned
Status: Needs work » Needs review
a.dmitriiev’s picture

Version: 1.2.x-dev » 1.3.x-dev
Status: Needs review » Reviewed & tested by the community

I have done the LIVE testing with chat and also Agents with tools. Everything works properly. Moving to RTBC.

marcus_johansson’s picture

Added two NITs, but will keep it in RTBC. Feel free to fix or to merge.

ahmad-khalil-imagex’s picture

Assigned: Unassigned » ahmad-khalil-imagex
ahmad-khalil-imagex’s picture

Assigned: ahmad-khalil-imagex » Unassigned
a.dmitriiev’s picture

Status: Reviewed & tested by the community » Fixed

Thank you @ahmad-khalil-imagex. This is getting merged. Added to merge train.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

arianraeesi’s picture

Status: Fixed » Closed (fixed)