Improve Dev experience with object style access for response models - #48363
Draft
Shivakishore14 wants to merge 3 commits into
Draft
Improve Dev experience with object style access for response models#48363Shivakishore14 wants to merge 3 commits into
Shivakishore14 wants to merge 3 commits into
Conversation
Keep request payloads dict-native while exposing response protocol models as dict-backed objects with attribute access and dictionary conversion helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 9 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Clarify that CreateResponse construction now returns a dict-native request payload while response models retain object-style access. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cover multi-turn scenarios where response model output is passed into a later CreateResponse payload and normalized back to wire dictionaries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
This PR restores object-style ergonomics for public Responses protocol response models while keeping the TypedDict/wire-native direction for request payloads and internal processing.
The TypedDict migration changes both request and response construction compared with the pre-TypedDict generated model stack:
CreateResponse(...),ItemMessage(...), andResponseObject(...)all returned generated model objects with attribute access.CreateResponse(...)remain plain dictionaries, while response protocol payloads such asItemMessage(...)andResponseObject(...)regain dict-backed object access.This keeps the useful part of the TypedDict approach and adds a thin compatibility layer for response payloads:
CreateResponseremain dict-nativeResponseModelobjectsitem.content[0].textto_dict()/as_dict()to_wire_dict()Before and after
Request construction
Request construction is intentionally changed from generated model object to dict-native payload:
This aligns with the OpenAI Python SDK pattern where request parameters are TypedDict-like.
Response model construction
Response model construction keeps the pre-TypedDict object-style ergonomics while remaining wire-serializable:
Why
The Responses package is a protocol/server framework, so JSON-shaped internal payloads are valuable for validation, persistence, streaming, replay, SSE, and storage serialization. However, requiring users to inspect response payloads through deeply nested dictionary access is a reduced SDK experience:
With this PR, public response payloads can keep the more familiar object-style access:
This better matches the OpenAI Python SDK split where request parameters are TypedDict-like, but response objects provide runtime model ergonomics.
Changes
ResponseModel, a dictionary-backed object model with:to_dict()andas_dict()helpersazure.ai.agentserver.responses.modelsexports so generated response-shape classes are replaced by namedResponseModelsubclasses.CreateResponseas plain dict-native TypedDict constructors.Validation
Ran targeted tests from
sdk/agentserver/azure-ai-agentserver-responses:Result: