Repository navigation
Description
Description
When using AG-UI (AgentFrameworkAgent / run_agent_stream) with tools that require human approval (approval_mode="always_require"), approved tools are executed on the resume/Allow path before agent.run(...).
That local approval execution builds tool runtime kwargs only from AG-UI run_kwargs (typically session / tools / options). It does not carry the documented tool runtime context that applications pass via agent.run(..., function_invocation_kwargs={...}).
As a result, tools that correctly read runtime-only values from FunctionInvocationContext.kwargs (for example user_id) work during the normal in-agent.run tool loop, but on the AG-UI Approve/resume path those same keys are missing from ctx.kwargs.
Expected behavior
After a user approves a pending tool call over AG-UI, the local approved-tool execution should see the same tool runtime context (FunctionInvocationContext.kwargs) that the application associates with the agent run via function_invocation_kwargs (as documented for function tools / runtime context).
Actual behavior
On the AG-UI resume/Allow path, approved tools are invoked with custom_args derived from run_kwargs only. Documented runtime values such as user_id from function_invocation_kwargs are not present on ctx.kwargs for that execution.
Relevant code (current mainline layout)
python/packages/ag-ui/agent_framework_ag_ui/_agent_run.pyrun_agent_stream: resolves/executes approval responses before callingagent.run(...)_resolve_approval_responses: buildstool_kwargsfromrun_kwargs(excludingoptions) and passes them ascustom_argsinto_try_execute_function_call_groups
Contrast with documented Agent API
@tool
def get_weather(location: str, ctx: FunctionInvocationContext) -> str:
user_id = ctx.kwargs.get("user_id", "unknown")
...
await agent.run(
"What is the weather like in Amsterdam?",
function_invocation_kwargs={"user_id": "user_123"},
)In a normal Agent.run tool loop, user_id is available on ctx.kwargs. On the AG-UI Approve/resume local-execution path, the equivalent runtime context is not available to the same tool.
Code Sample
Minimal shape (conceptual):
- Expose an AG-UI agent with a tool that uses
ctx: FunctionInvocationContextand readsctx.kwargs["user_id"](or any key supplied only viafunction_invocation_kwargs). - Drive a turn that hits
approval_mode="always_require"so the run finishes with a pending approval / interrupt. - Resume/Allow the pending approval through AG-UI.
- Observe that during local approved-tool execution,
ctx.kwargsdoes not contain the runtime key thatfunction_invocation_kwargsis documented to provide for tool invocation.
Error Messages / Stack Traces
No framework crash is required. The failure mode is missing runtime context on FunctionInvocationContext.kwargs during AG-UI approved-tool execution (application-level permission / identity checks then fail or fall back incorrectly).
Package Versions
agent-framework-core: 1.15.0
agent-framework-ag-ui: 1.2.0
Python Version
Python 3.14.2
Additional Context
This is specific to the AG-UI approval / resume local-execution path, not to plain Agent.run HITL handling that stays inside a single agent.run tool loop.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
jstar0 commentedon Sep 8, 2026
I'd like to take this on.
Proposed scope:
function_invocation_kwargsinto the AG-UI approval/resume local execution path, without conflating it withrun_kwargsor theoptionscontrol surface;Agent.runpath and the current AG-UI resume semantics;FunctionInvocationContext.kwargs, proving the runtime context survives the approval boundary.I will keep the change focused on the Python AG-UI adapter and its tests, then run the relevant
uv run poe syntaxand unit-test commands. If this direction is acceptable, please assign the issue to me or confirm that I should proceed.likebean commentedon Sep 14, 2026
Evan Mattson (@moonbox3) Eduard van Valkenburg (@eavanvalkenburg) This was filed as a Python bug and initially typed as Bug, then changed to Feature.
Please reclassify it as Bug. This is not a new capability:
function_invocation_kwargsis already the documented way to pass runtime identity intoFunctionInvocationContext.kwargs.user_idduring the in-agent.runtool loop, but loses it on the AG-UI Approve/resume local-execution path.The missing plumbing in
_resolve_approval_responses(custom_argsbuilt fromrun_kwargsonly) is the defect. A focused fix does not expand the public API.