Skip to content

Conversation

@mikeas1
Copy link
Contributor

@mikeas1 mikeas1 commented Jul 29, 2025

A refactor of the refactor.

This pulls out the common code from across transport-specific clients into one BaseClient, then shoves all the transport-specific code into implementations of ClientTransport.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @mikeas1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've undertaken a significant refactoring of the client architecture to improve modularity and maintainability. The core change involves separating the common client logic from the transport-specific communication details. I've introduced a BaseClient to handle shared functionalities and a ClientTransport interface that defines how different protocols interact with the agent. Existing transport implementations have been migrated to adhere to this new ClientTransport interface, and the ClientFactory has been updated to dynamically assemble clients using these new, specialized transport components. This change results in a cleaner, more extensible, and easier-to-maintain client codebase.

Highlights

  • Introduction of BaseClient: I've introduced a new BaseClient class that encapsulates all the common, transport-agnostic logic previously duplicated across different client implementations. This centralizes shared functionalities like event consumption and task management.
  • Creation of ClientTransport Interface: To cleanly separate transport-specific concerns, I've defined a new abstract base class, ClientTransport. This interface outlines the methods required for any communication transport (e.g., sending messages, getting tasks, handling streaming).
  • Migration to Dedicated Transport Implementations: The existing gRPC, JSON-RPC, and REST client implementations have been refactored into new, dedicated GrpcTransport, JsonRpcTransport, and RestTransport classes, respectively. Each of these now implements the ClientTransport interface, handling the specific network communication details for their protocol.
  • Updated ClientFactory for Modular Client Creation: The ClientFactory has been updated to leverage this new architecture. Instead of creating monolithic client instances, it now selects and instantiates the appropriate ClientTransport based on the agent's capabilities and the client's configuration, and then wraps it within a BaseClient instance. This makes client creation more flexible and extensible.
  • Removal of Old Client Implementations: The previous, tightly coupled client implementations (grpc_client.py, jsonrpc_client.py, rest_client.py) have been removed, streamlining the codebase and eliminating redundancy.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and well-executed refactoring of the client architecture, separating transport-independent logic into a BaseClient and isolating protocol-specific details into ClientTransport implementations. This is a great improvement for modularity and extensibility. My review focuses on a few potential issues in the new gRPC transport that could lead to incorrect behavior or resource leaks, and a concern about reduced test coverage for the JSON-RPC transport.

@mikeas1
Copy link
Contributor Author

mikeas1 commented Jul 30, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the client implementation, separating transport-agnostic logic into a BaseClient and transport-specific details into ClientTransport implementations, which improves modularity and maintainability. The addition of an integration test suite is a good step towards ensuring the stability of this new architecture. The RestTransport does not implement interceptors, and there is a large block of duplicated code in one of the new test files.

Comment on lines 75 to 146
from unittest.mock import AsyncMock, MagicMock

import httpx
import pytest

from a2a.client import A2AClient, A2AGrpcClient
from a2a.types import (
AgentCapabilities,
AgentCard,
GetTaskRequest,
Message,
MessageSendParams,
Part,
Role,
SendMessageRequest,
Task,
TaskQueryParams,
TaskState,
TaskStatus,
TextPart,
)


@pytest.fixture
def mock_httpx_client() -> AsyncMock:
return AsyncMock(spec=httpx.AsyncClient)


@pytest.fixture
def mock_grpc_stub() -> AsyncMock:
stub = AsyncMock()
stub._channel = MagicMock()
return stub


@pytest.fixture
def jsonrpc_agent_card() -> AgentCard:
return AgentCard(
name='Test Agent',
description='A test agent',
url='http://test.agent.com/rpc',
version='1.0.0',
capabilities=AgentCapabilities(streaming=True),
skills=[],
default_input_modes=[],
default_output_modes=[],
preferred_transport='jsonrpc',
)


@pytest.fixture
def grpc_agent_card() -> AgentCard:
return AgentCard(
name='Test Agent',
description='A test agent',
url='http://test.agent.com/rpc',
version='1.0.0',
capabilities=AgentCapabilities(streaming=True),
skills=[],
default_input_modes=[],
default_output_modes=[],
preferred_transport='grpc',
)


@pytest.mark.asyncio
async def test_a2a_client_send_message(
mock_httpx_client: AsyncMock, jsonrpc_agent_card: AgentCard
):
client = A2AClient(
httpx_client=mock_httpx_client, agent_card=jsonrpc_agent_card
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This block of code appears to be a copy-paste of the setup code from lines 1-74. This duplication should be removed to improve the test file's clarity and maintainability.

@holtskinner holtskinner changed the title feat: Refactor client into BaseClient + ClientTransport refactor: Refactor client into BaseClient + ClientTransport Jul 30, 2025
@mikeas1 mikeas1 marked this pull request as ready for review July 30, 2025 16:03
@mikeas1 mikeas1 requested a review from a team as a code owner July 30, 2025 16:03
@mikeas1 mikeas1 merged commit c2f4f2f into a2aproject:restful Jul 30, 2025
2 checks passed
mikeas1 added a commit that referenced this pull request Jul 30, 2025
refactor: Update client code to support multi-transport
refactor: Refactor client into BaseClient + ClientTransport
#363

---------

Co-authored-by: pstephengoogle <pstephen@google.com>
Co-authored-by: swapydapy <swapnilag@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: kthota-g <kcthota@google.com>
Co-authored-by: Aneesh Garg <1320714+aneeshgarg@users.noreply.github.com>
Co-authored-by: Mike Smith <mikeas@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants