Skip to content

Python: A2AAgent: forward selected run kwargs in request metadata #7973

Description

Description

A2AAgent.run() accepts function_invocation_kwargs and client_kwargs for interface compatibility but sends nothing over A2A. When an A2AAgent is a workflow participant, the runtime context a caller passes through workflow.run(function_invocation_kwargs=..., client_kwargs=...) never reaches the remote A2A server, so a remote agent behaves differently from a local one.

These two kwargs, together with session, stream and the messages, are the whole SupportsAgentRun.run contract, so they are the natural carrier. The A2A protocol has a request-level SendMessageRequest.metadata field (a Struct, exposed server-side as RequestContext.metadata) that A2AAgent never sets and that is not part of the message or task history.

Proposal

Let an A2AAgent opt in to forwarding selected keys of those two kwargs, sent as SendMessageRequest.metadata["agent_framework"] = {"function_invocation_kwargs": {...}, "client_kwargs": {...}}:

  • Opt-in via an explicit key allowlist (A2AAgent(..., forwarded_kwargs=[...])). Nothing is sent by default, so credentials or other local objects in kwargs are never serialized to a remote service.
  • Only values a protobuf Struct can carry exactly (JSON-compatible, finite numbers, integers within +/-2**53), with a clear error otherwise.
  • Not placed in HTTP headers or in Message.metadata.
  • Works through workflow.run(...), including per-executor targeting.

The server side is tracked in #9191.

Code Sample

agent = A2AAgent(url="https://remote-agent", forwarded_kwargs=["tenant"])

await workflow.run("Process the request.", function_invocation_kwargs={"tenant": "acme"})

Language/SDK

Python

Activity

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

    @UniversePeak
    Contributor

    Thanks for the detailed reproduction. I verified the current main path: A2AAgent._prepare_message_for_a2a() already copies the explicit Message.additional_properties["a2a_metadata"] mapping to the outbound A2A message, while A2AExecutor.execute() creates the session immediately before _run()/_run_stream() and has no pre-execution hook. I also found no open PR or commit linked to #7973.

    I can contribute the smallest focused implementation once the API direction is confirmed. My proposed slice is:

    1. Keep arbitrary function_invocation_kwargs out of transport. Add an explicit, JSON-safe a2a_metadata input at the A2AAgent boundary (or document/reuse the existing message-level a2a_metadata path if maintainers prefer), and cover both regular and streaming sends without changing unrelated headers.
    2. Add an awaited A2AExecutor session-preparation extension point that runs after create_session(...) and before _run/_run_stream, receiving the inbound RequestContext and newly-created AgentSession. The default remains a no-op, so existing users are unaffected.
    3. Add focused unit tests proving that selected metadata arrives at the remote A2A message and that the hook can populate session state before agent execution, including the streaming path where applicable.

    Could a maintainer confirm the preferred public API/signature and whether this issue should be assigned to me for implementation? I will keep the change limited to the Python A2A package and its tests, and document that only explicitly selected JSON-compatible application data is transmitted.

  3. added
    a2aUsage: [Issues, PRs], Target: A2A
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Aug 31, 2026
  4. changed the title [-]Python: Add A2A metadata hooks for cross-agent runtime context[/-] [+]Python: A2AAgent: send request metadata over A2A from client_kwargs[/+] on Oct 8, 2026
  5. changed the title [-]Python: A2AAgent: send request metadata over A2A from client_kwargs[/-] [+]Python: A2AAgent: forward selected run kwargs over A2A request metadata[/+] on Oct 8, 2026
  6. changed the title [-]Python: A2AAgent: forward selected run kwargs over A2A request metadata[/-] [+]Python: A2AAgent: forward selected run kwargs in request metadata[/+] on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

a2aUsage: [Issues, PRs], Target: A2ApythonUsage: [Issues, PRs], Target: Python

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions