Python: update FoundryAgent for hosted agent sessions#5447
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Automated Code Review
Reviewers: 3 | Confidence: 92%
✗ Correctness
The
_handle_inner_agentmethod in_responses.pyhas an invertedisinstance(self._agent, RawAgent)check: it warns and skips options forRawAgent(which supportsoptionsin.run()— see_agents.py:896) and passes options to non-RawAgentagents (whoseSupportsAgentRun.run()at_agents.py:271-278has nooptionsparameter). This inverts the correct old behavior. The corresponding tests were updated to match the inverted logic (usingraw_agent=False), masking the bug. The rest of the changes (FoundryAgentOptions, service session management, extra_body merging, allow_preview plumbing) look correct.
✓ Test Coverage
The PR adds substantial new functionality (FoundryAgentOptions, service session management, extra_body merging, conversation_id suppression) with generally good test coverage for the happy paths. However, there are notable test gaps: the streaming
_parse_chunk_from_openaioverride has zero test coverage despite being a mirror of the tested_parse_response_from_openai; theallow_preview=Truebranch that preserves tools/tool_choice in_prepare_optionsis untested; andget_agent_version()error paths (TypeError raises) lack coverage. The_responses.pyrefactoring inverts the RawAgent/non-RawAgent options-forwarding logic, and the test was updated to match the new non-RawAgent path, but no test verifies the new RawAgent warning behavior.
✗ Design Approach
I found two design-level problems in the new hosted-session path. The first is a real identity mix-up: the code now allows the local wrapper
nameto diverge from the remote Foundryagent_name, but the new session-management methods call the service withself.name, so a custom display name will target the wrong hosted agent. The second is an abstraction mismatch around preview enablement: the docs say a caller can pass an already preview-configuredproject_client, but the implementation gates hosted-session behavior off the wrapper'sallow_previewflag instead of the supplied client capability, so that path is disabled unless callers redundantly set both.
Suggestions
- Add a streaming-path test for
_parse_chunk_from_openaianalogous totest_raw_foundry_agent_chat_client_parse_response_suppresses_conversation_id_for_agent_sessions— the conversation_id suppression logic is identical but has zero test coverage. - Model preview enablement as a single source of truth — either require the wrapper flag consistently and document it, or derive capability from the supplied
project_client— so calers don't need to configure both.
Automated review by eavanvalkenburg's agents
187de20 to
d3abef4
Compare
Co-authored-by: Copilot <copilot@github.com>
Remove the public hosted-agent service session CRUD helpers from FoundryAgent and drop the related feature-stage inventory entry. Update the hosted-agent sample to create and delete service sessions directly through the preview AIProjectClient APIs, and tighten a few test harnesses surfaced by full workspace validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
34813e0 to
0363a42
Compare
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Previous commit incorrectly renamed the [1.1.1] header to [1.2.0], which wiped the historical 1.1.1 entries and wrongly attributed them to 1.2.0. This restores [1.1.1] to its origin/main content and adds a new [1.2.0] section above containing only the commits in python-1.1.1..HEAD: - microsoft#4238 functional workflow API - microsoft#5142 GitHub Copilot OpenTelemetry - microsoft#2403 A2A bridge support - microsoft#5070 oauth_consent_request events in Foundry clients - microsoft#5447 FoundryAgent hosted agent sessions - microsoft#5459 hosting server dependency upgrade + types - microsoft#5389 AG-UI reasoning/multimodal parsing fix - microsoft#5440 stop [TOOLBOXES] warning spam - microsoft#5455 user agent prefix fix Also corrects the [1.2.0] compare base to python-1.1.1 (not 1.1.0) and adds the missing [1.1.1] reference link.
* Bump Python package versions for 1.2.0 release Released tier bumps 1.1.1 -> 1.2.0 (core, openai, foundry, root) to reflect additive public APIs landed since 1.1.0: functional workflow API (#4238) and FunctionTool SKIP_PARSING sentinel (#5424). All beta packages stamped 1.0.0b260424, alpha packages 1.0.0a260424. All 26 non-core agent-framework-core floors raised to >=1.2.0,<2. CHANGELOG consolidates the never-tagged 1.1.1 entries with the post-merge additions into [1.2.0]. * Update CHANGELOG footer links for 1.2.0 Advance [Unreleased] comparison base from python-1.1.0 to python-1.2.0 and add a [1.2.0] reference link comparing python-1.1.0...python-1.2.0 so the heading links resolve correctly. * Fix CHANGELOG: restore [1.1.1] section and add proper [1.2.0] Previous commit incorrectly renamed the [1.1.1] header to [1.2.0], which wiped the historical 1.1.1 entries and wrongly attributed them to 1.2.0. This restores [1.1.1] to its origin/main content and adds a new [1.2.0] section above containing only the commits in python-1.1.1..HEAD: - #4238 functional workflow API - #5142 GitHub Copilot OpenTelemetry - #2403 A2A bridge support - #5070 oauth_consent_request events in Foundry clients - #5447 FoundryAgent hosted agent sessions - #5459 hosting server dependency upgrade + types - #5389 AG-UI reasoning/multimodal parsing fix - #5440 stop [TOOLBOXES] warning spam - #5455 user agent prefix fix Also corrects the [1.2.0] compare base to python-1.1.1 (not 1.1.0) and adds the missing [1.1.1] reference link.
Motivation and Context
Foundry hosted agents now rely on preview session APIs, and the current Python Foundry agent and sample flow did not handle lazy service session creation or the new hosted request payload shape. This change aligns the Foundry agent, foundry_hosting server, and hosted-agent samples with the new hosted-agent flow.
Description
Closes: #5416
Contribution Checklist