Python: Align Responses hosting parser semantics - #7966
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Aligns Python Responses hosting helpers with OpenAI request and output semantics.
Changes:
- Adds official
conversationhandling and stricter request validation. - Preserves output boundaries, status, metadata, and usage while rejecting unsupported output.
- Updates tests, specifications, and samples.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
python/samples/04-hosting/af-hosting/local_responses/README.md |
Updates continuation terminology. |
python/samples/04-hosting/af-hosting/local_responses/app.py |
Updates conversation documentation. |
python/samples/04-hosting/af-hosting/local_responses_workflow/README.md |
Documents unsupported conversation continuation. |
python/samples/04-hosting/af-hosting/local_responses_workflow/call_server.py |
Updates client comments. |
python/samples/04-hosting/af-hosting/local_responses_workflow/app.py |
Updates rejection messaging. |
python/samples/04-hosting/af-hosting/local_responses_harness/README.md |
Updates continuation terminology. |
python/samples/04-hosting/af-hosting/local_responses_harness/app.py |
Updates conversation documentation. |
python/packages/hosting-responses/tests/hosting_responses/test_parsing.py |
Expands parser and conversion coverage. |
python/packages/hosting-responses/tests/hosting_responses/test_http_round_trip.py |
Adds HTTP validation and conversation tests. |
python/packages/hosting-responses/README.md |
Documents official conversation semantics. |
python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py |
Implements validation and response conversion changes. |
docs/specs/002-python-hosting-channels.md |
Updates the hosting contract and example. |
Suppressed comments (1)
python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py:395
- The raw-field fallback does not work for finalized streams.
AgentResponse.from_updatesstores raw updates in a list, and agent updates wrap the provider event in anotherraw_representation; this code only inspects the list object itself. Consequently a real streamed terminal response can lose itsstatusandmetadata(for example, an upstreamfailedresponse is converted ascompleted). Traverse sequences and nestedraw_representation/responseobjects from the last update backward.
raw = result.raw_representation
for source in (raw, getattr(raw, "raw_representation", None)):
if isinstance(source, Mapping):
value = cast("Mapping[str, Any]", source).get(key)
else:
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (2 commit(s)): 278735180f9f, 31505a4331ab
Model: gpt-5.6-sol
Overview
The review found 3 verified inline finding(s).
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (1 high, 2 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
MAF Automated Review — Iteration 2
Result: Findings reported
Scope: 1 net-new commit(s): 32b856f7b8cb
Model: gpt-5.6-sol
Overview
This incremental update correctly separates raw transport status from flattened user metadata, accepts partial top-level usage counters, and aligns streaming terminal event types with final response status. The traversal and terminal-status tests provide strong coverage for the prior findings. One remaining usage edge case can serialize internally inconsistent token accounting when detail counters are present without their optional parent counters.
Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1fa98222-11d1-4116-99db-32de50d72dee
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1fa98222-11d1-4116-99db-32de50d72dee
Motivation & Context
The hosting Responses helpers accepted a nonstandard continuation field, silently chose between conflicting continuation mechanisms, and defaulted malformed message input. Final conversion also merged message boundaries, emitted fixed response fields even when
AgentResponsecarried real values, and represented ordinary media as fabricated function-call output.This aligns the helper-first hosting surface with the official OpenAI Responses request and output schemas while keeping the existing lightweight streaming design.
Description & Review Guide
conversationstring/object requests, reject conflicting continuation mechanisms, and retainconversation_idonly as a warned compatibility fallback.conversationdirectly. Existing standaloneconversation_idcallers continue to work with a deprecation warning.AgentResponsefields instead of fixed defaults.Related Issue
N/A
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.