Skip to content

Python: feat: forward function_invocation_kwargs through DevUI to agent.run - #7779

Merged
Evan Mattson (moonbox3) merged 4 commits into
microsoft:mainfrom
manjunathshiva:python-devui-forward-funkwargs-7344
Aug 21, 2026
Merged

Python: feat: forward function_invocation_kwargs through DevUI to agent.run#7779
Evan Mattson (moonbox3) merged 4 commits into
microsoft:mainfrom
manjunathshiva:python-devui-forward-funkwargs-7344

Conversation

@manjunathshiva

Copy link
Copy Markdown
Contributor

Motivation & Context

DevUI builds the kwargs passed to agent.run() by hand and only forwards stream and session, so tools that read request-scoped values via FunctionInvocationContext.kwargs (tenant id, auth token, user id) silently receive nothing when the agent is run through DevUI.

The same agent works correctly outside DevUI via a direct agent.run(..., function_invocation_kwargs=...) call. Parity matters when agents are first developed / debugged in DevUI before being promoted to a real deployment.

Fixes #7344.

Description & Review Guide

Two prior attempts exist for this issue (#7352 and #7355); both were closed by their authors (one a literal duplicate of the other) without maintainer review. This PR takes the smaller of the two approaches:

  • What are the major changes?

    • _executor.py (_execute_agent): read function_invocation_kwargs from the request and merge it into the kwargs passed to agent.run(). Accepts both channels already present on the request payload:
      • extra_body.function_invocation_kwargs — the channel already used for response_id and checkpoint_id in this file
      • a top-level extra field — AgentFrameworkRequest has model_config = ConfigDict(extra="allow"), so a top-level function_invocation_kwargs key was already accepted (and silently dropped, which is what the issue reporter originally tried)
    • Top-level takes precedence when both are set. Missing or non-dict values are silently ignored for backward compatibility.
    • tests/devui/test_execution.py: parametrized regression test asserting the kwarg reaches run() via both channels, and is not forwarded at all when absent.
  • What is the impact of these changes?

    • Additive and backward compatible. No AgentFrameworkRequest model change, no frontend changes — only the existing DevUI /v1/responses agent execution path gains forwarding behavior. When the field is absent, behavior is unchanged.
  • What do you want reviewers to focus on?

    • Whether accepting the value from both extra_body.function_invocation_kwargs and a top-level model_extra field is desired, or extra_body alone (the prior extra_body-only attempt in Python: Forward function_invocation_kwargs through DevUI to agent.run… #7352 may be what maintainers prefer; easy to narrow).
    • Whether forwarding should also be added to the workflow execution path (_execute_workflow) — intentionally left out of this PR since the issue is specifically about per-tool invocation context on the agent path.

Related Issue

Fixes #7344

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.

…nt.run

DevUI's /v1/responses endpoint builds agent.run() kwargs by hand and only
passed stream/session, so tools that read request-scoped values via
FunctionInvocationContext.kwargs (tenant id, auth token, user id)
silently received nothing when the agent was run through DevUI. The same
agent works correctly outside DevUI via agent.run(..., function_invocation_kwargs=...).

Forward function_invocation_kwargs from the request into agent.run() in
AgentFrameworkExecutor._execute_agent. Accepts both channels already used
on the request payload:
  - extra_body.function_invocation_kwargs (the channel already used for
    response_id / checkpoint_id)
  - top-level extra field (AgentFrameworkRequest has ConfigDict(extra="allow"))
Top-level takes precedence when both are set. Non-dict / missing values
are silently ignored for backward compatibility. No frontend / model
changes.

Adds a parametrized regression test in test_execution.py covering all
three cases (extra_body, top-level, absent).

Fixes microsoft#7344

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.

Pull request overview

Forwards request-scoped function invocation arguments from DevUI requests to agent tool invocations.

Changes:

  • Supports nested and top-level function_invocation_kwargs.
  • Adds regression coverage for both channels and omitted values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/devui/agent_framework_devui/_executor.py Forwards validated invocation kwargs to agent.run().
python/packages/devui/tests/devui/test_execution.py Tests forwarding and absence behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
TOTAL47338436990% 
report-only-changed-files is enabled. No files were changed during this commit :)

Python Unit Test Overview

Tests Skipped Failures Errors Time
9643 36 💤 0 ❌ 0 🔥 2m 33s ⏱️

@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Aug 21, 2026
Merged via the queue into microsoft:main with commit 24a3836 Aug 21, 2026
35 checks passed
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: [Feature]: DevUI doesn't accept function_invocation_kwargs

3 participants