Python: Discard non-copyable fields on Content deepcopy - #7898
Closed
Shivani . (Shivani767) wants to merge 1 commit into
Closed
Python: Discard non-copyable fields on Content deepcopy#7898Shivani . (Shivani767) wants to merge 1 commit into
Shivani . (Shivani767) wants to merge 1 commit into
Conversation
Stop shallow-sharing unsafe raw_representation during deepcopy. When a marked field cannot be deep-copied, set it to None and log a warning so clones are true deep copies.
Shivani . (Shivani767)
temporarily deployed
to
github-app-auth
August 27, 2026 06:25 — with
GitHub Actions
Inactive
Shivani . (Shivani767)
temporarily deployed
to
github-app-auth
August 27, 2026 06:25 — with
GitHub Actions
Inactive
Shivani . (Shivani767)
temporarily deployed
to
github-app-auth
August 27, 2026 06:26 — with
GitHub Actions
Inactive
Shivani . (Shivani767)
temporarily deployed
to
github-app-auth
August 27, 2026 06:26 — with
GitHub Actions
Inactive
Shivani . (Shivani767)
temporarily deployed
to
github-app-auth
August 27, 2026 06:26 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Pull request overview
Updates deepcopy behavior to discard non-copyable provider objects instead of retaining shared references.
Changes:
- Deep-copies copyable fields and replaces failing designated fields with
None. - Logs warnings when fields are discarded.
- Updates unit and workflow regression tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_types.py |
Updates Content deepcopy behavior. |
python/packages/core/agent_framework/_serialization.py |
Updates mixin deepcopy behavior. |
python/packages/core/tests/core/test_types.py |
Tests core response and content copying. |
python/packages/core/tests/core/test_serializable_mixin.py |
Tests generic mixin behavior. |
python/packages/core/tests/workflow/test_agent_executor.py |
Tests workflow handling of non-copyable responses. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+605
to
+609
| try: | ||
| object.__setattr__(result, k, deepcopy(v, memo)) | ||
| except Exception as exc: | ||
| if k not in unsafe: | ||
| raise |
Comment on lines
+302
to
+306
| try: | ||
| object.__setattr__(result, k, copy.deepcopy(v, memo)) | ||
| except Exception as exc: | ||
| if k not in unsafe: | ||
| raise |
5 tasks
Member
|
Closing this as a alternative PR already merged |
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
Content.__deepcopy__(andSerializationMixin.__deepcopy__) previously kept_SHALLOW_COPY_FIELDSsuch asraw_representationby reference. That created partially deep-copied objects and obscured deepcopy semantics when the field held non-copyable LLM SDK objects.Fixes #7851
Description & Review Guide
What are the major changes?
_SHALLOW_COPY_FIELDSfails to deepcopy, set it toNoneon the clone and log a warning.raw_representationvalues are still deep-copied normally.What is the impact of these changes?
raw_representationafter deepcopy will now seeNone(with a warning).What do you want reviewers to focus on?
None+ warning is preferable to raising, for workflow/checkpoint paths that deepcopy responses.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.