Repository navigation
Python: expose invocation identity through context metadata - #10047
Daniel Quintas (danielquintas8) wants to merge 3 commits into
Conversation
|
@microsoft-github-policy-service agree |
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): ea8d8696f2ab
Model: gpt-5.6-sol
Overview
The change exposes the provider call ID through a read-only context property and preserves the existing middleware metadata contract, with broad coverage across direct, middleware, streaming, and approval-resume paths. Initialization, automatic invocation, and successful standalone reuse are guarded well. One validation-ordering gap leaves a previous call ID on a reused standalone context when a later invocation fails before dispatch, which can miscorrelate failed calls.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/core/agent_framework/_tools.py
|
Daniel Quintas (@danielquintas8) Maintainer direction: do not add a dedicated |
|
Updated in e1730ef9 to follow the metadata direction. Both automatic paths populate Local verification passed 9,347 core tests, syntax checks, strict source typing, all five test typing profiles, and wheel/sdist builds. Core and adversarial reviews passed with no findings. Credential-dependent integration tests were not run. |
Motivation & Context
A context-aware tool needs the provider call ID to correlate its execution with the recorded call and result. The automatic loop already puts this ID in metadata when function middleware is registered. Tools on the path without middleware need the same documented metadata.
Description & Review Guide
What are the major changes? Document
FunctionInvocationContext.metadata["call_id"]as the provider correlation ID andmetadata["function_call_occurrence_id"]as the canonicalContent.id, when present. Populate these entries before middleware and tool execution on both automatic paths, including approval resume. StandaloneFunctionTool.invokesets or clears the provider ID from its existingtool_call_idargument before validation. It retains supplied occurrence metadata only when the context's provider ID matches that argument. Changing or omitting the provider ID clears the occurrence entry.What is the impact of these changes? Context-aware tools can read invocation identity without registering middleware. The change uses the existing metadata mapping and adds no context property. Regression tests cover streaming, approval resume, reused provider IDs, standalone context reuse, and rejected invocations. The full core suite, syntax checks, strict source Pyright, and all five test type checkers pass locally. Credential-dependent integration tests were not run.
What do you want reviewers to focus on? Check identity availability before middleware and tool execution, canonical occurrence IDs when provider IDs repeat, and metadata clearing before validation on reused standalone contexts.
Related Issue
Fixes #9454
The metadata API follows the core team's direction.
AI Assistance
AI assistance details: implementation, regression tests, documentation, and this PR description.
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.