Skip to content

Python: [Bug]: AG-UI local approval execution does not receive function_invocation_kwargs / tool runtime context #8132

Description

@likebean

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.py
    • run_agent_stream: resolves/executes approval responses before calling agent.run(...)
    • _resolve_approval_responses: builds tool_kwargs from run_kwargs (excluding options) and passes them as custom_args into _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):

  1. Expose an AG-UI agent with a tool that uses ctx: FunctionInvocationContext and reads ctx.kwargs["user_id"] (or any key supplied only via function_invocation_kwargs).
  2. Drive a turn that hits approval_mode="always_require" so the run finishes with a pending approval / interrupt.
  3. Resume/Allow the pending approval through AG-UI.
  4. Observe that during local approved-tool execution, ctx.kwargs does not contain the runtime key that function_invocation_kwargs is 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.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Sep 8, 2026
  2. jstar0 commented on Sep 8, 2026

    @jstar0
    Contributor

    I'd like to take this on.

    Proposed scope:

    • thread the run's function_invocation_kwargs into the AG-UI approval/resume local execution path, without conflating it with run_kwargs or the options control surface;
    • preserve the existing plain Agent.run path and the current AG-UI resume semantics;
    • add a regression tool whose approved execution reads a marker from 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 syntax and unit-test commands. If this direction is acceptable, please assign the issue to me or confirm that I should proceed.

  3. added
    ag-uiUsage: [Issues, PRs], Target: AG-UI protocol integration
    on Sep 8, 2026
  4. removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Sep 8, 2026
  5. likebean commented on Sep 14, 2026

    @likebean
    Author

    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_kwargs is already the documented way to pass runtime identity into FunctionInvocationContext.kwargs.
    • The same tool receives user_id during the in-agent.run tool loop, but loses it on the AG-UI Approve/resume local-execution path.
    • After Allow, tools cannot see the current user. That is a broken existing contract (identity / authorization), not a feature request.

    The missing plumbing in _resolve_approval_responses (custom_args built from run_kwargs only) is the defect. A focused fix does not expand the public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ag-uiUsage: [Issues, PRs], Target: AG-UI protocol integrationpythonUsage: [Issues, PRs], Target: Python

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions