Python: [Feature]: Publish which arguments an invocation's variable expansion rewrote - #8506
Open
pratik wayase (PratikWayase) wants to merge 1 commit into
Open
pratik wayase (PratikWayase) wants to merge 1 commit into
pratik wayase (PratikWayase) wants to merge 1 commit into
Conversation
pratik wayase (PratikWayase)
deployed
to
github-app-auth
September 18, 2026 09:46 — with
GitHub Actions
Active
pratik wayase (PratikWayase)
deployed
to
github-app-auth
September 18, 2026 09:46 — with
GitHub Actions
Active
pratik wayase (PratikWayase)
deployed
to
github-app-auth
September 18, 2026 09:46 — with
GitHub Actions
Active
Copilot started reviewing on behalf of
pratik wayase (PratikWayase)
September 18, 2026 09:47
View session
pratik wayase (PratikWayase)
deployed
to
github-app-auth
September 18, 2026 09:47 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Integer-keyed dictionaries are incorrectly reported as list positions rather than non-list arguments.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds a public security API for identifying arguments rewritten by variable expansion.
Changes:
- Tracks rewritten argument paths in security middleware.
- Exposes rewrite indices through
rewritten_arguments(). - Adds coverage for lists, scalars, dictionaries, and threaded execution.
File summaries
| File | Description |
|---|---|
python/packages/core/agent_framework/security.py |
Implements tracking, context propagation, and the public accessor. |
python/packages/core/tests/test_security.py |
Tests rewrite reporting across supported scenarios. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1634
to
+1635
| if len(path) > 1 and isinstance(path[1], int): | ||
| rewritten_args[arg_name].add(path[1]) |
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
LabelTrackingFunctionMiddlewareexpands[var_xxx]references into a tool's arguments before the body runs. From 1.18,PolicyEnforcementFunctionMiddlewarerefuses forwarding that content unless the destination tool opts in (accepts_untrusted=True).However, a tool that opts in has no supported way to ask which of its arguments the expansion rewrote. The tool body just sees ordinary strings. This creates a security gap: if a tool needs to refuse a bad file name and names it in the error message, it might accidentally echo hidden, untrusted content back into the conversation.
This PR provides a supported, public API for tools to identify exactly which argument positions were produced by the framework, allowing them to render safe indices (e.g.,
files[0]) instead of quoting the hidden text.Description & Review Guide
What are the major changes?
rewritten_arguments(context=None)toagent_framework.security._current_contextContextVarinsecurity.pyto securely propagate theFunctionInvocationContexttorewritten_arguments(), supporting both explicit context passing and implicitasyncio.to_threadusage.LabelTrackingFunctionMiddleware._resolve_valueand_resolve_stringto track the exact paths of expanded variables._expand_variable_references_in_contextto map these paths to adict[str, set[int]]stored incontext.metadata.What is the impact of these changes?
{"files": {0, 2}}) and-1for scalar or dictionary arguments (e.g.,{"text": {-1}}).What do you want reviewers to focus on?
_resolve_valueand howcurrent_pathtuples are constructed._expand_variable_references_in_contextthat convertspath[1]into the integer index for lists, or falls back to-1for non-lists.asyncio.to_threadtest to ensure theContextVarcorrectly copies to worker threads.Related Issue
Closes #8342
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.