Skip to content

Python: Update hosting agent samples + fixes#5485

Merged
TaoChenOSU merged 7 commits intomainfrom
taochen/python-hosting-agent-update-samples
Apr 28, 2026
Merged

Python: Update hosting agent samples + fixes#5485
TaoChenOSU merged 7 commits intomainfrom
taochen/python-hosting-agent-update-samples

Conversation

@TaoChenOSU
Copy link
Copy Markdown
Contributor

@TaoChenOSU TaoChenOSU commented Apr 25, 2026

Motivation and Context

Current samples don't align with samples in other Azure repositories. There are also defects in the responses host.

Description

  1. Update foundry hosting agent samples to align with the samples in other Azure repos.
  2. Fix file content type support and add more tests.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@TaoChenOSU TaoChenOSU self-assigned this Apr 25, 2026
Copilot AI review requested due to automatic review settings April 25, 2026 00:19
@moonbox3 moonbox3 added the documentation Improvements or additions to documentation label Apr 25, 2026
@github-actions github-actions Bot changed the title Update hosting agent samples + fixes Python: Update hosting agent samples + fixes Apr 25, 2026
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 25, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry_hosting/agent_framework_foundry_hosting
   _responses.py52411478%151–152, 161–162, 166, 171, 185, 209, 235–237, 256–258, 260–262, 264–266, 270–273, 276–281, 288, 293, 296, 303–304, 306–307, 309, 311, 313–316, 318–320, 324, 327–334, 337–338, 340–341, 349–354, 426–427, 1072–1074, 1076, 1123–1124, 1126–1127, 1129–1130, 1132–1133, 1138, 1147, 1150–1152, 1154, 1172, 1175, 1210–1214, 1218–1224, 1231–1235, 1241–1247, 1254, 1260, 1263
TOTAL29883347988% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
6029 30 💤 0 ❌ 0 🔥 1m 42s ⏱️

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 84%

✓ Correctness

The PR adds file_data support for the input_file content type in the Responses hosting layer, refactors samples (renaming env vars, switching to DefaultAzureCredential, reorganizing directories), adds integration test infrastructure for foundry_hosting, and updates CI workflows. The core logic in _convert_file_data and the input_file/input_image changes are correct: data URIs route through Content.from_uri which correctly classifies them as type data, text/* files are decoded to plain text, and the MessageContentInputFileContent model does have file_data and filename attributes (verified against source). No blocking correctness issues found.

✓ Security Reliability

The PR adds file_data (base64 data URI) support, integration tests, CI workflow changes, and sample updates. The main reliability concern is in _convert_file_data where base64.b64decode().decode('utf-8') can raise unhandled UnicodeDecodeError or binascii.Error on malformed input at the HTTP trust boundary. The remaining changes (env var renames, credential switch to DefaultAzureCredential, README updates, workflow configs) are straightforward and carry no security or reliability risk.

✓ Test Coverage

The new _convert_file_data function has two distinct code paths (text/* decode vs. URI passthrough), but the only unit test exercises the non-text branch (application/pdf). The text/* branch — which base64-decodes content and returns Content.from_text() — is covered only by integration tests that require live credentials. Additionally, the media_type="image/*" change to Content.from_uri for input_image has no unit-level verification. The integration test suite (test_responses_int.py) is thorough and well-structured.

✗ Design Approach

I found two design-level issues worth addressing before merging. The new file_data conversion path special-cases all text/* uploads by decoding them as UTF-8 text, which is a losy workaround on top of a content layer that already knows how to preserve data URIs as typed data content. Separately, the new MCP sample now silently drops its only remote tool when GITHUB_PAT is missing, which turns a misconfigured MCP sample into an apparently healthy plain-chat sample instead of failing fast.

Suggestions

  • The media_type="image/*" argument to Content.from_uri for input_image prevents _validate_uri from extracting the specific media type (e.g. image/jpeg) from data URIs, because extraction only occurs when media_type is None (_types.py:247). Consider omitting media_type for data URIs or letting validation extract it automatically.

Automated review by TaoChenOSU's agents

Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Comment thread python/packages/foundry_hosting/tests/test_responses.py
@TaoChenOSU TaoChenOSU moved this to In Progress in Agent Framework Apr 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 50 out of 63 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (2)

python/samples/04-hosting/foundry-hosted-agents/invocations/README.md:1

  • This file is now empty. If the content was intentionally moved to the parent README, consider either deleting this README entirely or leaving a short pointer to the parent README so users who land here don’t get a blank page.
    python/samples/04-hosting/foundry-hosted-agents/responses/README.md:1
  • This file is now empty. If the content was intentionally moved to the parent README, consider either deleting this README entirely or leaving a short pointer to the parent README so users who land here don’t get a blank page.

Comment thread python/samples/04-hosting/foundry-hosted-agents/responses/01_basic/README.md Outdated
Comment thread python/samples/04-hosting/foundry-hosted-agents/responses/02_tools/README.md Outdated
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
@TaoChenOSU TaoChenOSU marked this pull request as ready for review April 27, 2026 16:54
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by TaoChenOSU's agents

@TaoChenOSU TaoChenOSU added this pull request to the merge queue Apr 27, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 27, 2026
@TaoChenOSU TaoChenOSU enabled auto-merge April 28, 2026 03:52
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Apr 28, 2026
Merged via the queue into main with commit 88347f6 Apr 28, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Agent Framework Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants