feat: add a TextClient class for a simplified text-based communication#963
feat: add a TextClient class for a simplified text-based communication#963sokoliva wants to merge 5 commits intoa2aproject:1.0-devfrom
TextClient class for a simplified text-based communication#963Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/client/client_factory.py | 88.67% | 88.89% | 🟢 +0.22% |
| src/a2a/client/text_client.py (new) | — | 84.62% | — |
| Total | 92.53% | 92.48% | 🔴 -0.05% |
Generated by coverage-comment.yml
There was a problem hiding this comment.
Code Review
This pull request introduces TextClient, a facade that simplifies text-based communication by aggregating response parts into a single string, and refactors the existing CLI sample to use message utilities. It includes a new sample CLI, factory methods, and unit tests. Feedback suggests improving lifecycle management via the asynchronous context manager protocol, refining response aggregation to handle streamed tokens correctly, and utilizing existing utilities to reduce code duplication in the new client.
|
|
||
|
|
||
| async def create_text_client( # noqa: PLR0913 | ||
| agent: str | AgentCard, |
There was a problem hiding this comment.
agent word is too broad. Can we do ?
| agent: str | AgentCard, | |
| agent_card: str | AgentCard, |
There was a problem hiding this comment.
agent can also be the base URL of the agent so renaming it to agent_card could be misleading. WDYT?
There was a problem hiding this comment.
You are right. I just noticed optional str. My bad! Let's keep it as it but add 2 example in doc-string.
>>> create_text_client('http://..'
....
>>>
>>> create_text_client(agent=my_agent_card,...)
|
|
||
| config = ClientConfig(supported_protocol_bindings=['JSONRPC']) | ||
|
|
||
| text_client = await create_text_client(card, client_config=config) |
There was a problem hiding this comment.
Hi, when I do
text_client = await create_text_client(
agent=SERVER_URL,
client_config=ClientConfig(streaming=False, supported_protocol_bindings="JSONRPC")
)I get
Traceback (most recent call last):
....
....
....
File ".../a2a/client/client_factory.py", line 360, in create
return BaseClient(
card,
...<2 lines>...
interceptors or [],
)
TypeError:
TypeError: BaseClient.__init__() missing 1 required positional argument: 'interceptors'
…to reduce-boilerplate
|
Not proceeding with this. |
Description
This feature dramatically reduces the complexity for common text-only exchanges, improving developer experience.
Changes
TextClient, a facade aroundClientthat simplifies text-basedcommunication by hiding proto construction, stream iteration, and
multi-part text aggregation behind a single
send_text_messagemethod.create_text_clientfactory function mirroringcreate_client,and export both from
a2a.client.samples/text_client_cli.pyas a minimal worked example, andsamples/README.mddocumenting all three sample files.samples/cli.pyto iterateStreamResponsedirectly anduse the shared
get_message_texthelper.Tested
Output from running simple
text_client_cli.pyOutput from running non-simplified
cli.pyFixes #959 🦕