Python: Forward GitHub Copilot input attachments as inline blobs#7300
Merged
Conversation
The Python GitHubCopilotAgent built the prompt from message text only, so DataContent (images/documents) passed on input was silently dropped. The .NET provider already forwards these as attachments. Map input data content to the Copilot SDK's inline BlobAttachment (base64, no temp files) in both the streaming and non-streaming send paths. Data content without a media type is dropped with a warning instead of silently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac85c429-4115-42ef-a18a-f576e3cf03f7
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
giles17
marked this pull request as ready for review
July 23, 2026 18:19
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Python GitHub Copilot provider support for forwarding inline binary DataContent (e.g., images/documents) as Copilot SDK inline blob attachments, closing parity with the .NET Copilot provider and preventing silent attachment loss.
Changes:
- Add
_prepare_attachments_for_copilot(...)to scan outgoingMessage.contentsfordatacontent and convert it to Copilot SDKBlobAttachmentobjects (base64 payload + MIME type). - Wire attachment forwarding into both non-streaming (
send_and_wait) and streaming (send) request paths. - Add unit tests covering non-streaming, streaming, text-only (no attachments), and missing-media-type behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/github_copilot/agent_framework_github_copilot/_agent.py | Builds and passes Copilot SDK attachments from inline data content for both streaming and non-streaming runs. |
| python/packages/github_copilot/tests/test_github_copilot_agent.py | Adds test coverage validating blob attachment forwarding and the missing-media-type behavior. |
Address PR review feedback: - Guard _get_data_bytes_as_str against ContentError so a non-base64 data: URI (which _validate_uri still classifies as type="data") is skipped with a warning instead of failing the entire Copilot request. - Correct the docstring: remote URIs and non-base64 data URIs are neither attached nor added to the prompt (the prompt is built from text content only). - Add tests for the non-base64 data URI path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac85c429-4115-42ef-a18a-f576e3cf03f7
The end-to-end non-base64 data URI test failed in CI because GitHubCopilotAgent's telemetry layer serializes message content (observability._to_otel_part -> _get_data_bytes_as_str), which raises ContentError on a non-base64 data: URI before the attachment code runs. That is an unrelated core-observability limitation, not attachment behavior. Use RawGitHubCopilotAgent (no telemetry layer) for that test so it isolates the provider's send path. The direct helper test still covers the ContentError guard. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac85c429-4115-42ef-a18a-f576e3cf03f7
This was referenced Jul 23, 2026
TaoChenOSU
approved these changes
Jul 23, 2026
chetantoshniwal
approved these changes
Jul 23, 2026
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.
Motivation & Context
The Python
GitHubCopilotAgentbuilt the outgoing prompt purely from messagetext, so any
DataContent(images, documents, and other inline binary content)passed on input was silently dropped — a user attaching an image received no
error and nothing reached Copilot. This closes that functional gap and removes
the silent data loss ahead of the 1.0 release.
Description & Review Guide
What are the major changes?
RawGitHubCopilotAgent._prepare_attachments_for_copilot(...), whichscans outgoing messages for
datacontent and maps each to the Copilot SDK'sinline
BlobAttachment(base64 payload + MIME type).send_and_wait(...)(non-streaming)and
send(...)(streaming).data:content is forwarded. Data content with no media type,and malformed / non-base64
data:URIs, are skipped with a warning ratherthan raising (a non-base64
data:URI is classified astype="data"but hasno base64 payload, so extracting its bytes would otherwise error).
https://links) are not forwarded and are not added tothe prompt, which is built from text content only.
missing media type, and the non-base64
data:URI case.What is the impact of these changes?
the behavior activates automatically for messages that already carry
DataContent. Non-breaking.What do you want reviewers to focus on?
datacontent toBlobAttachment, and the handling ofunsupported/edge content (skip-with-warning rather than raising).
Related Issue
No existing tracking issue yet. Happy to open one and link it with a closing
keyword if preferred.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.