Skip to content

Python: Forward function_invocation_kwargs to GitHubCopilotAgent tools - #8868

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
droideronline:feature/copilot-function-invocation-kwargs
Oct 1, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
droideronline:feature/copilot-function-invocation-kwargs

Conversation

@droideronline

Copy link
Copy Markdown
Contributor

Motivation & Context

function_invocation_kwargs passed to a GitHubCopilotAgent (directly via agent.run(...), or from a workflow via workflow.run(..., function_invocation_kwargs=...)) never reached its tools. RawGitHubCopilotAgent.run accepted them only through **kwargs and dropped them, and the Copilot SDK tool handler called FunctionTool.invoke without a FunctionInvocationContext. Tools that declare a FunctionInvocationContext parameter therefore saw empty ctx.kwargs and no ctx.session, unlike the same tool on a chat-client-backed Agent.

Description & Review Guide

  • What are the major changes?
    • RawGitHubCopilotAgent.run (all overloads) now takes function_invocation_kwargs as a named parameter and forwards it to _run_impl and _stream_updates.
    • The value, together with the current AgentSession, is threaded through _get_or_create_session, _create_session / _resume_session, _build_session_kwargs and _prepare_tools into _tool_to_copilot_tool.
    • The tool handler builds a FunctionInvocationContext(function, arguments, session, kwargs) and passes it to ai_func.invoke(...), along with the SDK's tool_call_id for telemetry.
  • What is the impact of these changes?
    • Tools that declare a FunctionInvocationContext parameter now receive the run's function_invocation_kwargs and session, matching core Agent behavior. Tools without a context parameter are unaffected, and the context parameter is not exposed in the tool schema sent to the model.
    • Tools are rebuilt on every session create/resume, so each run's handlers capture that run's kwargs.
  • What do you want reviewers to focus on?
    • Passing the AgentSession to tools via ctx.session, and the new keyword-only parameters on the private session and tool helpers.

Tests added for non-streaming and streaming runs, resumed sessions, and tools without a context parameter.

Related Issue

Fixes #8865

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 is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • 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.

RawGitHubCopilotAgent.run swallowed function_invocation_kwargs in **kwargs
and the Copilot SDK tool handler invoked FunctionTool without a
FunctionInvocationContext, so tools never saw per-run kwargs or the
AgentSession. Thread both through session create/resume into the tool
handler and pass them via FunctionInvocationContext.

Fixes microsoft#8865

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 reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 29, 2026
…sion

The Copilot SDK keeps one session object per service session ID and
re-registers tools on every resume, dispatching tool calls by session ID.
Since tool handlers now capture the run's function_invocation_kwargs and
session, an overlapping resume could let one run's tool calls execute with
another run's context. Hold a per-session run lock from create/resume until
the run completes.
@droideronline

Copy link
Copy Markdown
Contributor Author

Fixed the failing "Test Typing Checks" job in 0eb1e19: the overlapping-run tests now use asyncio.ensure_future for agent.run(...) (typed as Awaitable, not a coroutine) and a named mock_on instead of the append(...) or lambda. No library code changed. Also merged latest main.

Merged via the queue into microsoft:main with commit f1fb145 Oct 1, 2026
44 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 0eb1e196 Deployed Oct 1, 2026 by droideronline via add_label #24154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: GitHubCopilotAgent drops function_invocation_kwargs before tool invocation

4 participants