Skip to content

Python: expose invocation identity through context metadata - #10047

Open
Daniel Quintas (danielquintas8) wants to merge 3 commits into
microsoft:mainfrom
danielquintas8:feature/function-call-id
Open

Daniel Quintas (danielquintas8) wants to merge 3 commits into
microsoft:mainfrom
danielquintas8:feature/function-call-id

Conversation

@danielquintas8

@danielquintas8 Daniel Quintas (danielquintas8) commented Nov 3, 2026 •

Copy link
Copy Markdown

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 and metadata["function_call_occurrence_id"] as the canonical Content.id, when present. Populate these entries before middleware and tool execution on both automatic paths, including approval resume. Standalone FunctionTool.invoke sets or clears the provider ID from its existing tool_call_id argument 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

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, regression tests, documentation, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@danielquintas8

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@eavanvalkenburg

Copy link
Copy Markdown
Member

Daniel Quintas (@danielquintas8) Maintainer direction: do not add a dedicated FunctionInvocationContext.call_id or call_content property in this PR. Use the existing metadata entries as the documented API and populate them consistently on every execution path: context.metadata["call_id"] for the provider correlation value, and context.metadata["function_call_occurrence_id"] for the canonical Content.id when function-call content exists. The direct invocation path must set or clear these values just like the middleware path. Please update the specification, tests, and PR description to match.

@danielquintas8 Daniel Quintas (danielquintas8) changed the title Python: expose provider call IDs on FunctionInvocationContext Python: expose invocation identity through context metadata Nov 6, 2026
@danielquintas8

Copy link
Copy Markdown
Author

Updated in e1730ef9 to follow the metadata direction. Both automatic paths populate call_id and function_call_occurrence_id before middleware and tool execution, using the canonical Content.id when present. The proposed property is removed. The specification, tests, and PR description now document the metadata API. Standalone invocation updates or clears identity before validation.

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.

This branch was previously deployed

1 inactive deployment
github-app-auth — e1730ef9 Deployed Nov 6, 2026 by danielquintas8 via add_label #27287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Feature]: Expose the tool call's id on FunctionInvocationContext on every execution path

3 participants