Repository navigation
Add native OpenAI compaction to LanguageModel - #8893
Closed
danieljvdm wants to merge 1 commit into
Closed
danieljvdm wants to merge 1 commit into
danieljvdm wants to merge 1 commit into
Conversation
Add provider-neutral compaction and opaque Prompt/Response parts with typed unsupported-operation failures. Preserve the complete OpenAI replacement window, exact model affinity, and available usage on rejection. Send compact requests as JSON and reject stateful replay shortcuts. Include the narrow generated transport fix and failure-first transport and decoder regressions.
🦋 Changeset detectedLatest commit: 9caf126 The changes in this PR will be included in the next version bump. This PR includes changesets to release 32 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
Contributor
|
As discussed, we will add this at a later point when we get to adding agent primitives. |
This branch had an error being deployed
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
Add
LanguageModel.compactand atomic opaque-context parts to the shared AI model. The OpenAI adapter sends JSON to the stateless/responses/compactendpoint and returns the complete replacement prompt, effective provider/model affinity, and usage. Useresult.promptas the next input window rather than appending it to the old history.Retained text messages, reasoning, ordinary function calls/string results, and compaction items round-trip without reordering or rewriting wire strings. Ordinary results belong in tool messages. Unsupported items and extensions fail instead of being dropped, with independently readable usage preserved even when returned context or usage detail is invalid. Providers without a compaction hook reject opaque-context inference before transport.
Replay requires the same effective provider/model and the complete returned window. Compaction does not execute historical tools, change Chat history, or update response-ID tracking. Conversation, previous-response, and explicit item-reference shortcuts are incompatible with native context; the original input must still fit the model's context window.
Validation
The transport/complete/streaming decoder regressions, affected runtime and type checks, and a local HTTP workflow pass. The workflow checks the entire ordered replacement window through Prompt serialization, repeated compaction, and text/structured/streamed replay, including affinity rejection and usage-preserving failures.
Bounded live OpenAI workflows with
gpt-5.4-miniverified standalone compaction, exact Prompt serialization, and next-inference replay for provider-generated and portable history. The final usage validator received an additional compact-only check: six paid requests in total. These checks establish availability and replay for those inputs, not compaction quality, speed, or token savings.Limits and release notes
The configured Stainless spec URL returns 404. The generation source now pins a public OpenAI snapshot, and only the compact transport delta was regenerated. Full provider regeneration remains blocked by the existing JSON-Schema importer's
CreateAssistantRequest.tool_resources.file_searchintersection handling. The compact transport change overlaps one hunk of #6678; this does not import its broad refresh.The changesets request a minor release for
effectand@effect/ai-openai. These APIs are unreleased; downstream publication requires a release containing them and matching dependency requirements. Custom services must supply the newcompactorcompactResponsemember, and exhaustive matches must handle thecompactionpart andUnsupportedOperationErrorreason.