feat(ai): switch OpenAI provider to responses API - #1457
Merged
Conversation
Keep OpenAI-compatible tool loops aligned with the Responses API by reusing previous response state and handling attachments more reliably across providers.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the OpenAI text provider implementation from Chat Completions to the OpenAI Responses API, adding provider-scoped state to support smaller tool-loop follow-ups via previous_response_id, and improving attachment handling by inlining text-like documents as prompt text.
Changes:
- Add
ProviderStatetocontracts/ai.AgentPromptand implement a conversation-scoped, thread-safe provider state map. - Update the OpenAI provider to build Responses API
inputitems, parse Responsesoutput(including tool calls), and stream via Responses SSE events. - Update tests to validate Responses API request bodies, tool call behavior, and
previous_response_idcontinuation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
contracts/ai/provider.go |
Adds ProviderState interface and threads it through AgentPrompt. |
ai/provider_state.go |
Implements a thread-safe map-backed provider state used by conversations. |
ai/openai/response.go |
Extends OpenAI response struct to track response IDs (used internally). |
ai/openai/provider.go |
Core migration to OpenAI Responses API (prompt, stream, tool calls, attachments, continuation). |
ai/openai/provider_test.go |
Updates prompt/stream tests to assert Responses API payloads and parsing. |
ai/openai/provider_tool_test.go |
Updates tool tests and adds coverage for previous_response_id in prompt/stream tool loops. |
ai/conversation.go |
Allocates and passes per-conversation ProviderState; resets state on Reset(). |
ai/conversation_test.go |
Updates expected provider calls to include ProviderState. |
ai/application_test.go |
Updates expected prompt payloads to include ProviderState. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1457 +/- ##
==========================================
+ Coverage 69.29% 69.36% +0.06%
==========================================
Files 364 365 +1
Lines 28713 28795 +82
==========================================
+ Hits 19897 19973 +76
- Misses 7924 7928 +4
- Partials 892 894 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
LinboLen
added a commit
to LinboLen/framework
that referenced
this pull request
May 3, 2026
* origin/master: fix(ai): remove context from image response content (goravel#1462) feat(ai): support provider-managed files (goravel#1460) feat(ai): add image generation support (goravel#1461) fix: [goravel#946] stop WithContext from leaking framework context keys (goravel#1456) feat(ai): add attachment upload support (goravel#1459) feat(ai): add attachment helper subpackages (goravel#1458) feat(ai): switch OpenAI provider to responses API (goravel#1457) feat(ai): add attachment support (goravel#1455)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
previous_response_idand only send tool outputs on follow-up requests.Why
The OpenAI provider was still speaking the older Chat Completions shape, which meant Goravel could not match the Responses API behavior now expected by OpenAI-compatible backends. This updates the provider to send Responses input items, parse Responses output and stream events, and keep tool-call continuation aligned with
previous_response_idso follow-up tool requests stay small and consistent.This also fixes two compatibility issues in real user flows. Before, tool loops had to rebuild growing request bodies instead of resuming from the prior OpenAI response, and plain-text documents such as
123.txtwere uploaded asinput_file, which some OpenAI-compatible providers reject unless the file is a PDF. After this change, tool continuations reuse provider state throughAgentPrompt.ProviderState, and text-like documents are sent as prompt text while PDFs and other binary files continue to use file attachments.