Skip to content

Python: Forward function_invocation_kwargs through DevUI to agent.run… - #7352

Open
atty57 wants to merge 1 commit into
microsoft:mainfrom
atty57:fix/devui-function-invocation-kwargs-7344
Open

Python: Forward function_invocation_kwargs through DevUI to agent.run…#7352
atty57 wants to merge 1 commit into
microsoft:mainfrom
atty57:fix/devui-function-invocation-kwargs-7344

Conversation

@atty57

@atty57 atty57 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

DevUI couldn't forward function_invocation_kwargs. It built the agent run kwargs by hand and passed only stream/session to agent.run(), so tools that read request-scoped values via FunctionInvocationContext a tenant id, auth token, user id received nothing when the agent was run through DevUI. The same agent works correctly outside DevUI via agent.run(..., function_invocation_kwargs=...), which made DevUI unusable for any agent whose tools depend on invocation context. This affects both the chat UI and the OpenAI-compatible /v1/responses endpoint.

Fixes #7344.

Description & Review Guide

  • 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(). Accepted from either extra_body.function_invocation_kwargs (the same channel already used for response_id / checkpoint_id) or a top-level function_invocation_kwargs field (model_extra) in the shape the issue reporter originally tried.
    • tests/devui/test_execution.py: a parametrized test that drives a recording agent through execute_streaming and asserts the kwargs reach run(); covers both channels and fails without the fix.
  • This is a backend-only change; the frontend / DevUI web UI was not touched. Passing function_invocation_kwargs now works over the API (e.g. /v1/responses with the field in extra_body or top-level). Adding a UI input for it is intentionally left out of this PR, since where it belongs (per-message vs per-session) is an open UX decision; happy to follow up separately if maintainers want it.

  • What is the impact of these changes?

    • Additive and backward compatible; when the field is absent, behavior is unchanged. No public API signature changes (uses the existing extra_body extensibility).
  • What do you want reviewers to focus on?

    • Whether accepting the value from both channels (extra_body and top-level model_extra) is desired, or extra_body alone.

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.

…() (microsoft#7344)

DevUI built the agent run kwargs by hand and forwarded only `stream` and
`session`, so tools that read request-scoped values via
FunctionInvocationContext never received them.

Read `function_invocation_kwargs` from the request — `extra_body` (the same
channel as response_id/checkpoint_id) or a top-level field — and merge it into
the kwargs passed to `agent.run()`. Adds a parametrized test covering both
channels.
Copilot AI review requested due to automatic review settings July 27, 2026 23:32
@atty57
atty57 temporarily deployed to github-app-auth July 27, 2026 23:32 — with GitHub Actions Inactive
@atty57
atty57 temporarily deployed to github-app-auth July 27, 2026 23:32 — with GitHub Actions Inactive
@atty57
atty57 temporarily deployed to github-app-auth July 27, 2026 23:32 — with GitHub Actions Inactive
@atty57
atty57 temporarily deployed to github-app-auth July 27, 2026 23:32 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Jul 27, 2026

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

This PR fixes DevUI request forwarding so function_invocation_kwargs reaches agent.run(...), enabling tools that rely on FunctionInvocationContext.kwargs (e.g., tenant/user/auth request-scoped values) to behave the same when invoked via DevUI as they do when agents are executed directly.

Changes:

  • Forward function_invocation_kwargs from the incoming DevUI/OpenAI-compatible request into the agent.run() kwargs in _executor.py.
  • Add a parametrized test verifying forwarding works when provided via extra_body.function_invocation_kwargs and via a top-level extra field.

Reviewed changes

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

File Description
python/packages/devui/agent_framework_devui/_executor.py Forwards request-scoped function_invocation_kwargs into agent.run() kwargs.
python/packages/devui/tests/devui/test_execution.py Adds regression test coverage ensuring forwarded kwargs reach the agent run call.

Comment on lines +382 to +388
fik = None
if request.extra_body:
fik = request.extra_body.get("function_invocation_kwargs")
if fik is None and request.model_extra:
fik = request.model_extra.get("function_invocation_kwargs")
if isinstance(fik, dict):
run_kwargs["function_invocation_kwargs"] = fik
Comment on lines +610 to +622
captured: dict[str, Any] = {}

class RecordingAgent:
"""Agent that records the kwargs its run() is called with."""

id = "kwargs_test"
name = "Kwargs Test Agent"
description = "Records run() kwargs"

def run(self, messages=None, *, stream=False, session=None, **kwargs):
captured.update(kwargs)
return self._stream_impl(messages)

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

2 participants