Skip to content

Python A2A: Expose supported_protocol_bindings as configurable parameter#6098

Open
giles17 wants to merge 2 commits into
microsoft:mainfrom
giles17:a2a-protocol-bindings
Open

Python A2A: Expose supported_protocol_bindings as configurable parameter#6098
giles17 wants to merge 2 commits into
microsoft:mainfrom
giles17:a2a-protocol-bindings

Conversation

@giles17
Copy link
Copy Markdown
Contributor

@giles17 giles17 commented May 26, 2026

Description

Expose supported_protocol_bindings as a configurable parameter on A2AAgent.__init__(), allowing users to specify which A2A protocol bindings the client prefers when connecting to remote agents.

Motivation

Per the A2A v1.0 specification (Section 5), agents can declare multiple protocol interfaces (JSONRPC, GRPC, HTTP+JSON) in their AgentCard. Clients need a way to express their binding preference for transport negotiation.

This was previously hardcoded to JSONRPC. This PR makes it user-configurable while preserving the default behavior.

Changes

  • Added supported_protocol_bindings: list[str] | None = None parameter to A2AAgent.__init__()
  • Resolves to ["JSONRPC"] by default (backward-compatible)
  • Passes through to ClientConfig for transport negotiation with the A2A SDK
  • Replaced 4 hardcoded JSONRPC references with the configurable value
  • Added 2 unit tests (custom bindings, default behavior)

.NET Parity

Aligns with .NET's A2AClientOptions.PreferredBindings from the A2A SDK NuGet package.

Type of Change

  • Feature

Process

  • Associated with an issue
  • Unit tests added
  • pyright clean
  • All existing tests pass

Add supported_protocol_bindings parameter to A2AAgent.__init__() allowing
users to configure which A2A protocol bindings (JSONRPC, GRPC, HTTP+JSON)
the client prefers when connecting to remote agents.

- Defaults to ["JSONRPC"] matching current behavior
- Passes through to ClientConfig for transport negotiation
- Replaces 4 hardcoded references with the configurable value

Closes microsoft#6057

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 26, 2026 21:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes Python A2AAgent transport negotiation configurable by exposing supported_protocol_bindings, while preserving the existing JSONRPC default.

Changes:

  • Adds supported_protocol_bindings to A2AAgent.__init__().
  • Threads the configured bindings into minimal_agent_card() and streaming/non-streaming ClientConfig.
  • Adds unit tests for custom bindings and default JSONRPC behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/a2a/agent_framework_a2a/_agent.py Adds and applies configurable A2A protocol binding preferences.
python/packages/a2a/tests/test_a2a_agent.py Adds initialization tests for custom and default protocol bindings.

Comment thread python/packages/a2a/agent_framework_a2a/_agent.py
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented May 26, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/a2a/agent_framework_a2a
   _agent.py2871893%181, 383, 388, 390, 434–435, 588, 604, 612, 632, 653, 681, 697, 707, 718, 725–726, 767
TOTAL36377431388% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
7259 34 💤 0 ❌ 0 🔥 1m 54s ⏱️

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 90%

✓ Correctness

Clean, straightforward change that replaces 4 hardcoded JSONRPC references with a user-configurable parameter. The default behavior is preserved via supported_protocol_bindings or ["JSONRPC"], the variable is correctly scoped before both code branches that use it, and the tests verify both custom and default paths. No correctness issues found.

✓ Security Reliability

The PR is a clean, low-risk feature addition. It correctly uses None as the default to avoid mutable default argument issues, consistently threads the configured bindings through all four usage sites, and includes appropriate tests. No security or reliability concerns identified.

✓ Test Coverage

The PR adds two well-structured tests verifying custom and default protocol bindings are passed to ClientConfig. However, test coverage has a gap: the transport negotiation fallback path (the except block at line ~183 in the diff that creates a fallback_card with bindings) is not exercised with custom bindings. Additionally, the or pattern (supported_protocol_bindings or ["JSONRPC"]) means an explicitly passed empty list [] silently defaults to ["JSONRPC"], which is an untested edge case that may surprise users.

✗ Design Approach

The overall approach is sound, but the new defaulting logic silently overrides one caller-suplied value: passing an explicit empty list for supported_protocol_bindings is treated the same as omitting the parameter, so the feature is not fully configurable for all values accepted by its own signature.

Flagged Issues

  • Explicit supported_protocol_bindings=[] is silently rewritten to ['JSONRPC'] in python/packages/a2a/agent_framework_a2a/_agent.py:134 because or treats an empty list as falsy. This means the API's type signature (list[str] | None) accepts a value it cannot faithfully represent. Default only when the parameter is None.

Automated review by giles17's agents

- Use 'is not None' check instead of 'or' to preserve explicit empty list
- Add test verifying empty list is not silently replaced with defaults
- Add test verifying fallback path uses custom bindings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants