Repository navigation
Python: A2AExecutor: accept forwarded run kwargs from request metadata - #9193
Conversation
|
Eduard van Valkenburg (@eavanvalkenburg) Evan Mattson (@moonbox3) - I would appreciate if you could take a look at this one and #9192 when you get a chance, we are in need for these two. thanks! |
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (2 commit(s)): 0dcc5a5a6be5, 243b12d994b1
Model: gpt-5.6-sol
Overview
The PR adds a default-off, allowlist-gated path for forwarding selected request metadata into agent run kwargs, with server-configured values taking precedence and malformed metadata ignored. The fresh per-request merge, explicit reserved keys, and streaming/non-streaming tests provide useful guardrails. One residual collision remains: because one allowlist governs both forwarded destinations, a remote caller can place an allowed framework-owned name in client_kwargs and reliably fail the task.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/a2a/agent_framework_a2a/_a2a_executor.py
Add an overridable hook called after the session is created and before the agent runs so applications can initialize session state from the inbound request.
Replace the prepare_session hook with opt-in acceptance of selected function_invocation_kwargs and client_kwargs keys read from the agent_framework key of SendMessageRequest.metadata.
Fail fast at construction when accepted_kwargs contains a name the framework owns (stream, messages, options, session, middleware and similar) or an underscore-prefixed name, so a remote caller cannot cause duplicate keyword errors.
0184cbd to
235184c
Compare
…kwargs independently A single accepted_kwargs allowlist let a remote caller inject a tool-context key into client_kwargs, which reaches the chat client. Replace it with accepted_function_invocation_kwargs and accepted_client_kwargs, both empty by default.
Pass the allowlists as explicit keyword arguments so pyright, ty and zuban can check the call.
…on' into feature/a2a-executor-prepare-session
|
The pipeline failure is fixed. The The only other failure was |
Motivation & Context
A2AExecutorreceives the inboundRequestContext, includingcontext.metadata(SendMessageRequest.metadata), but ignores it, andrun_kwargsis fixed at construction. Runtime context a caller passes asfunction_invocation_kwargsandclient_kwargstherefore never reaches the hosted agent, so middleware and tools see differentcontext.kwargsthan they would locally. These two kwargs plussessionandstreamare the wholeSupportsAgentRun.runcontract.Description & Review Guide
A2AExecutor(accepted_function_invocation_kwargs=[...], accepted_client_kwargs=[...])options, two independent allowlists of key names.execute()readsSendMessageRequest.metadata["agent_framework"](written byA2AAgent(forwarded_kwargs=...)in Python: A2AAgent: forward selected run kwargs in request metadata #9192), keeps only the allowed keys offunction_invocation_kwargsandclient_kwargsaccording to their own allowlist, and passes them toagent.run(...)in both streaming and non-streaming mode.None) accepts nothing for both destinations, so behavior is unchanged.accepted_function_invocation_kwargsdoes not let the caller inject the same key intoclient_kwargs, which reaches the chat client. Keys configured inrun_kwargswin on conflict, framework-owned names such asstream,messages,options,sessionandmiddleware(and underscore-prefixed names) are rejected withValueErrorat construction in either allowlist, and missing or malformed metadata is ignored._runand_run_streamtake an optionalrun_kwargsargument that defaults to the configured kwargs, so existing callers are unaffected.agent_framework, which is defined separately in the client PR so the two PRs stay independent.Client side: #7973 and #9192.
Related Issue
Fixes #9191
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.