Skip to content

[Feat]: Reduced Boilerplate for A2A Python SDK Text Messaging #959

@msampathkumar

Description

@msampathkumar

Is your feature request related to a problem? Please describe.

While A2A provides robust message constructs, the process for a basic A2A Client to send and receive simple text messages currently requires excessive boilerplate. This feature dramatically reduces the complexity for common text-only exchanges, improving developer experience.

Here is a code sample from https://github.com/a2aproject/a2a-samples/blob/b5af0df12fe941ae79c52684fc1fd5357c4f88a6/samples/python/agents/helloworld/test_client.py#L58-L76

In the following code, we are sending a text message say hello. to the A2A server and print the response.

    client_factory = ClientFactory(config=ClientConfig(streaming=False))
    client = client_factory.create(_public_card)
    logger.info('\nNon-streaming A2AClient initialized.')

    parts = [Part(text='Say hello.')]
    message = Message(
        role=Role.ROLE_USER,
        parts=parts,
        message_id=uuid4().hex,
    )
    request = SendMessageRequest(message=message)

    response = client.send_message(request)

    async for chunk in response:
        print('Response:')
        task, _ = chunk
        print(task)

Problem: This is has many steps to do, methods or functions that users to know and a complex workflow to remember and follow.

Describe the solution you'd like

Request: Simplify this something like below

    client = A2AClient(
        agent_card=_public_card,				# Provide AgentCard information
        config=types.ClientConfig(streaming=False)	# Optional param - config
        )
    response = client.send_message(
        message=types.user_message(text='Say hello.')	# simple text message
        )
    print(response.text)						# provide a `.text` (property) to get access text immediately

Summary of Developer Improvements Requetss:
Simple jobs should be simple enough to do.

  • Provide a simple way to pack text input message

    Eliminate boilerplate by providing a simple utility, types.user_message(text=...), to construct text input without manually instantiating Part, Message, and SendMessageRequest objects.

  • Provide a simple way to get & print text output message

    Allow immediate, non-streaming access to the text output via a convenient .text property, simplifying response handling and eliminating the need for async chunk iteration in non-streaming scenarios.

Describe alternatives you've considered

No response

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions