Python: Forward function_invocation_kwargs through DevUI to agent.run… - #7352
Open
atty57 wants to merge 1 commit into
Open
Python: Forward function_invocation_kwargs through DevUI to agent.run…#7352atty57 wants to merge 1 commit into
atty57 wants to merge 1 commit into
Conversation
…() (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.
Contributor
There was a problem hiding this comment.
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_kwargsfrom the incoming DevUI/OpenAI-compatible request into theagent.run()kwargs in_executor.py. - Add a parametrized test verifying forwarding works when provided via
extra_body.function_invocation_kwargsand 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) | ||
|
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
DevUI couldn't forward
function_invocation_kwargs. It built the agent run kwargs by hand and passed onlystream/sessiontoagent.run(), so tools that read request-scoped values viaFunctionInvocationContexta tenant id, auth token, user id received nothing when the agent was run through DevUI. The same agent works correctly outside DevUI viaagent.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/responsesendpoint.Fixes #7344.
Description & Review Guide
What are the major changes?
_executor.py(_execute_agent): readfunction_invocation_kwargsfrom the request and merge it into the kwargs passed toagent.run(). Accepted from eitherextra_body.function_invocation_kwargs(the same channel already used forresponse_id/checkpoint_id) or a top-levelfunction_invocation_kwargsfield (model_extra) in the shape the issue reporter originally tried.tests/devui/test_execution.py: a parametrized test that drives a recording agent throughexecute_streamingand asserts the kwargs reachrun(); 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_kwargsnow works over the API (e.g./v1/responseswith the field inextra_bodyor 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?
extra_bodyextensibility).What do you want reviewers to focus on?
extra_bodyand top-levelmodel_extra) is desired, orextra_bodyalone.Related Issue
Fixes #7344
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.