Repository navigation
Add OpenAI decision client adapter - #7957
Open
luisquintanilla wants to merge 11 commits into
Open
luisquintanilla wants to merge 11 commits into
luisquintanilla wants to merge 11 commits into
Conversation
luisquintanilla
force-pushed
the
luisquintanilla-decision-model-abstraction
branch
from
November 18, 2026 03:40
24cff1a to
4ef177a
Compare
Contributor
Author
|
cc: @achandmsft |
luisquintanilla
force-pushed
the
luisquintanilla-decision-model-abstraction
branch
2 times, most recently
from
November 18, 2026 20:11
dac27e4 to
fa041dc
Compare
Adds an experimental AsIDecisionClient extension over OpenAI.Decisions.DecisionsClient. Maps JSON state, text, and image contents (data and URI, with optional detail) and binary, choice, and score questions to the Decisions API, and maps predicate, choice, score, and refusal answers back to the provider-neutral abstractions with validation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
FromOpenAIDecision already correlates answers by name in request order, checks kinds, and maps distributions into request order, so the DecisionResponse.Validate call is removed. Adds a test for an answer to a question that was not asked. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Follow the IDecisionClient rename in the abstractions. Update the OpenAI adapter, the decisions README sample, and the unit and integration tests. Chat client members are unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The service accepts only JSON objects as JSON input, so string state is now sent as text, null state is omitted, and other JSON values are sent as their JSON text. Add integration tests for record state, string state, and record state with image contents using the GetDecisionAsync state overload, and update the README sample to use it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
luisquintanilla
force-pushed
the
luisquintanilla-decision-model-abstraction
branch
from
November 18, 2026 21:08
fa041dc to
b91535f
Compare
- Questions the service did not answer become UnansweredDecisionAnswer. - Answers for questions that were not asked are ignored, and when a question is answered more than once the last answer wins. - Distributions are passed through as reported instead of being zero-filled and reordered to the request. - Kind mismatches and invalid values still throw InvalidOperationException. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…apter Adopt the updated DecisionRequest shape and Choice/Score constructor order from the base API, and take IList<AIContent> in the content helpers. Reject requests that provide neither state nor contents before any service call, and send explicit JSON-null state as raw JSON text instead of silently dropping it. Add focused tests and update the README. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
DecisionClientException was removed from the abstractions. Stop wrapping ClientResultException and drop the transient classification so SDK exceptions propagate unchanged, as the OpenAI chat adapters do. Argument validation and malformed-response checks are unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jozkee
approved these changes
Dec 3, 2026
…I choice and score questions Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been 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.
Stacked on #7795. Related to #7764.
Summary
This PR adds
AsIDecisionClient(), an experimental (MEAI001) extension that wrapsOpenAI.Decisions.DecisionsClientas anIDecisionClient. It is the first concrete implementation of the provider-neutral decision abstraction from #7795, so the abstraction's shape is checked against a real service.The adapter only translates. It maps the request to the OpenAI Decisions wire format and maps the native answers back. It also enforces the abstraction's response contract. It does not post-process probabilities.
The state is serialized with
AIJsonUtilities.DefaultOptions, asIChatClient.GetResponseAsync<T>does. For Native AOT, pass a source-generated context's options. For full control, construct aDecisionRequestwith aJsonElementState:new DecisionRequest(questions) { State = ..., Contents = ... }.With an OpenAI API key, it is
new DecisionsClient(apiKey).AsIDecisionClient("gpt-6-luna").What this PR adds
OpenAIClientExtensions.AsIDecisionClient(DecisionsClient, string? defaultModelId)[Experimental]and recorded inMicrosoft.Extensions.AI.OpenAI.json.OpenAIDecisionClient(internal)GetServiceDecisionClientMetadata(provideropenai, endpoint, default model, all three kinds) and the underlyingDecisionsClientMicrosoft.Extensions.AI.OpenAIREADMEHow the PRs fit together
Microsoft.Extensions.AI.AbstractionsMicrosoft.Extensions.AIAsAIFunctionMicrosoft.Extensions.AI.OpenAIThis PR is a draft because it depends on #7795 settling, and because the OpenAI .NET SDK's Decisions surface (OpenAI 2.15.0) is itself experimental.
Mapping
DecisionRequest.Stateinput_jsoncontent part for a JSON object. A JSON string is sent asinput_text. Other non-object values, including an explicit JSONnull, are sent asinput_textwith their raw JSON text. AnullState(no state) sends nothing.TextContentinput_textDataContentorUriContent, with an optional"detail"additional propertyinput_imageAIContent.RawRepresentationthat is already a native partBinaryDecisionQuestionpredicate. True and false descriptions are appended to the instructions, because predicates have no outcome descriptions.ChoiceDecisionQuestion/DecisionCandidatechoice/choices[].valueScoreDecisionQuestion/DecisionScoreLevelscore/levels[].labelDecisionOptions.ModelId,RawRepresentationFactorymodel, and a pre-populatedDecisionCreationOptionsrefusalanswerUnansweredDecisionAnswerwithDecisionUnansweredReason.RefusalconfidenceDecisionAnswer.AdditionalProperties["confidence"]usage, including cached and reasoning tokensUsageDetailsRawRepresentationon each answer and on the responseContract enforcement, errors and ownership
UnansweredDecisionAnswerwith no reason. Answers to questions that weren't asked are ignored, and if a name repeats, the last answer wins. An answer of the wrong kind throwsInvalidOperationException, because it can't be represented.0.1fmaps to0.1. Non-finite values throwInvalidOperationException, as do values the answer types reject, such as probabilities outside [0, 1].Stateisnull) and no contents throwsArgumentException(request) before any service call. Explicit JSON-null state counts as state, as Add experimental provider-neutral decision abstractions (Layer 1) #7795 documents.NotSupportedExceptionand is never dropped. Candidate and level descriptions must be text, because OpenAI supports only text there.ClientResultExceptionpropagate unchanged, as with the OpenAI chat adapters. The adapter does no wrapping or transient classification.DecisionsClient. Disposing the adapter does nothing.Changes since the previous revision
DecisionResponse.ValidateandUnansweredDecisionAnswer.Messagewere removedValidate; its own name-based correlation already enforces the contract. Added a test for an extra answer to a question that wasn't asked.JsonTypeInfo<TState>state overloads with default andJsonSerializerOptionsoverloads, mirroringIChatClient.GetResponseAsync<T>;DecisionRequestwith aJsonElementremains the escape hatchinput_jsonDecisionClientException(77484f3867)ClientResultExceptionwrapping and transient classification; service errors now propagate as SDK exceptions. The service-error test now assertsClientResultExceptionwith the original status.bc36be3e4e):DecisionRequest(questions) { State, Contents }, Choice/Score constructors take candidates or levels before instructions,IList<AIContent>content snapshots,DecisionResponse.ResponseIdremoved, and each implementation must validate that a request has state, contents, or bothIList<AIContent>; tests, integration tests, and README use the new shapes.GetDecisionAsyncthrowsArgumentExceptionfor a request with neither state nor contents, before building options or calling the service. Explicit JSON-null state was previously dropped, which would have sent an empty input; it is now sent asinput_textnull, and the unreachableUndefinedcase was removed. The adapter never mappedResponseId. Added tests for no input (null and empty contents), state only, JSON-null state only, and contents only.IDecisionClient.GetResponseAsynctoGetDecisionAsyncDecisionsClient.CreateDecisionAsynccall it wraps.DecisionProtocolExceptionand stopped requiring complete, request-ordered distributionsInvalidOperationException. Mapping is lenient where the response is still usable: missing answers become unanswered, extra answers are ignored, repeated names and IDs keep the last value, and distributions pass through as reported. The adapter still throws for a kind mismatch, a choice that isn't a string, and non-finite or out-of-range values.Suggested review focus
AdditionalProperties["confidence"]. Does it warrant a first-class property later?"detail"additional property on the content the right way to choose the detail level, consistent with the chat adapters?Review map
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIDecisionClient.cssrc/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIClientExtensions.cssrc/Libraries/Microsoft.Extensions.AI.OpenAI/Microsoft.Extensions.AI.OpenAI.jsonsrc/Libraries/Microsoft.Extensions.AI.OpenAI/README.mdtest/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIDecisionClientTests.cstest/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIDecisionClientIntegrationTests.csValidation and review
Validated locally at head
3bbb83549b(merge5f2c51479aof base77484f3867, plus the adapter change).Microsoft.Extensions.AI.OpenAIbuildOpenAIDecisionClientTests+OpenAIDecisionClientIntegrationTests(filtered)Microsoft.Extensions.AI.OpenAI.TestsMicrosoft.Extensions.AI.OpenAI.TestsWith the input check and JSON-null mapping reverted, the four affected unit-test cases fail (no state with null contents, no state with empty contents, JSON-null state only, and the JSON-null case of the per-kind mapping test).
Live tests were not run on this revision. No
OpenAI:*integration configuration was available, so the fiveOpenAIDecisionClientIntegrationTestswere skipped. In particular, whether the service acceptsinput_textnullas the only input is not yet validated live. The earlier live results (5/5 against Azure OpenAIgpt-6-lunaon net10.0 at6c43336080, plus probes for data-URI anddetail=lowimages, images in predicate instructions, zero-probability options, and score probabilities withvalueandlabel) predate this change. Three bugs found during those runs were fixed: a null image detail went through an implicit SDK conversion, a float-to-double conversion differed on net11.0, and non-object state was sent asinput_json.The integration tests are enabled through
OpenAI:Mode/OpenAI:EndpointplusOpenAI:DecisionModel. They are skipped otherwise.Service behavior. The deployment used for earlier validation reported zero output tokens, so
OutputTokenCountwas 0 in those runs. The adapter reports what the service returns.Hosted CI for this stacked draft is not claimed here. This does not constitute API review approval.