-
Notifications
You must be signed in to change notification settings - Fork 341
refactor: Refactor client into BaseClient + ClientTransport #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
BaseClientclass 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, andRestTransportclasses, respectively. Each of these now implements theClientTransportinterface, handling the specific network communication details for their protocol. - Updated ClientFactory for Modular Client Creation: The
ClientFactoryhas been updated to leverage this new architecture. Instead of creating monolithic client instances, it now selects and instantiates the appropriateClientTransportbased on the agent's capabilities and the client's configuration, and then wraps it within aBaseClientinstance. 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
-
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. ↩
There was a problem hiding this 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.
|
/gemini review |
There was a problem hiding this 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.
tests/client/test_legacy_client.py
Outdated
| 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 | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
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.