adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Propagate `Event.partial` through the A2A protocol

Open seandi opened this issue 1 year ago • 8 comments

Problem Description When an ADK Event emitted by a remote A2A agent is sent to a client agent using the A2A protocol, the Event.partial attribute of the server event is lost. This makes it impossible for the client application to recognize if the incoming text generation events from the server LLM are complete or not.

Possible solution A possible solution could be to encode the partial status of an Event in the metadata of the A2A message parts created from it, similarly to how it's done for propagating information on long-running tools in convert_a2a_message_to_event and convert_event_to_a2a_message.

Alternative solutions Include Event.partial to the set of attributes added to the TaskStatusUpdateEvent metadata (i.e. _get_context_metadata) and use the task metadata to reconstruct the Event on the client side. One possible downside of this approach is that according to the A2A specs this metadata should be reserved for extensions.

seandi avatar Oct 17 '25 10:10 seandi

@seandi Thanks for reporting this issue! To help us reproduce and validate it, could you please share a bit more details about your setup? Specifically: 1.The versions in use 2.How the server and client agents are configured in your test setup 3.The steps or code snippet that emits the Event.partial updates on the server side Thanks!

klateefa avatar Nov 03 '25 07:11 klateefa

We encountered this same issue while building an orchestrator agent that consumes remote A2A agents. Unfortunately I couldn't find adk a2a SSE examples and we had to go build some wrappers to make SSE work in ADK.

Here's our experience:

Problem 1: SSE Streaming Not Enabled by Default

Before we could even encounter the partial field issue, we had to work around the fact that RemoteA2aAgent has streaming hardcoded to False in the A2AClientConfig (line 206 of remote_a2a_agent.py):

# In google.adk.agents.remote_a2a_agent.RemoteA2aAgent._ensure_httpx_client()
client_config = A2AClientConfig(
    httpx_client=self._httpx_client,
    streaming=False,  # ← Hardcoded!
    polling=False,
    supported_transports=[A2ATransport.jsonrpc],
)

This prevents the client from subscribing to SSE streams even when the remote agent supports streaming.

Our Workaround: We created a custom StreamingRemoteA2aAgent that overrides _ensure_httpx_client():

Problem 2: Partial Field Not Propagated

Once we enabled streaming, we encountered this exact issue: Event.partial is lost during A2A conversion.

What we observed:

  • Server side (sub-agent): ADK emits multiple streaming events with Event.partial=True/False
  • Client side (orchestrator): Received Event.partial=None for all events

Looking into the Workaround propodes(following "Alternative Solution"): Extend CustomA2aAgentExecutor to detect LLM responses and add partial status to metadata:

In both agents we are using:

google-adk==1.18.0

Any Suggestions?

Is the a2a SSE going to be supported soon? Is this the best approach for now or do you recommend going into a different direction?

Thanks

ruibrasfernandes avatar Nov 07 '25 09:11 ruibrasfernandes

I can confirm that this issue is persisting as of google-adk==1.18.0. I will provide below the minimal setup for both server and client that allows to reproduce the issue.

Server setup

To setup an A2A remote agent with SSE streaming through the A2A protocol I had to make 3 changes with respect to the default settings:

  1. Enable streaming=True in the AgentCapabilities
  2. Create a custom request converter that sets streaming_mode=StreamingMode.SSE for the runner invocation
  3. Pass this converter to the A2aAgentExecutorConfig used by the A2aAgentExecutor

Running the snippet below will first run the agent locally, showing that it streams Event with Event.partial=True, then it will start a server exposing the same agent as an A2A remote agent.

from a2a.server.apps import A2AStarletteApplication
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.tasks import InMemoryTaskStore
from a2a.types import AgentCapabilities
from google.adk import Agent
from google.adk.a2a.converters.request_converter import AgentRunRequest, _get_user_id
from google.adk.a2a.executor.a2a_agent_executor import (
    A2aAgentExecutor,
    A2aAgentExecutorConfig,
)
from google.adk.a2a.utils.agent_card_builder import AgentCardBuilder
from google.adk.a2a.utils.agent_to_a2a import to_a2a
from google.adk.agents.run_config import RunConfig, StreamingMode
from google.adk.runners import Runner
from google.adk.sessions.in_memory_session_service import InMemorySessionService
from google.genai import types
from starlette.applications import Starlette

model = "configure your model here..."


# Steps required to enable SSE streaming for remote A2A agents:
# 1. Enable streaming=True in the AgentCapabilities
# 2. Create a custom request converter that sets streaming_mode=StreamingMode.SSE for the runner invocation
# 3. Pass this converter to the A2aAgentExecutorConfig used by the A2aAgentExecutor

root_agent = Agent(
    model=model,
    name="remote_agent",
    description=("Hell world agent that can tell jokes and stories."),
)


runner = Runner(
    app_name="remote_agent",
    agent=root_agent,
    session_service=InMemorySessionService(),
)


def convert_a2a_request_to_agent_sse_run_request(
    request,
    part_converter,
):

    if not request.message:
        raise ValueError("Request message cannot be None")

    custom_metadata = {}
    if request.metadata:
        custom_metadata["a2a_metadata"] = request.metadata

    return AgentRunRequest(
        user_id=_get_user_id(request),
        session_id=request.context_id,
        new_message=types.Content(
            role="user",
            parts=[part_converter(part) for part in request.message.parts],
        ),
        run_config=RunConfig(
            custom_metadata=custom_metadata, streaming_mode=StreamingMode.SSE
        ),
    )


async def get_app():
    card_builder = AgentCardBuilder(
        agent=root_agent,
        capabilities=AgentCapabilities(streaming=True),
        rpc_url="http://localhost:8001/",
    )

    agent_executor = A2aAgentExecutor(
        runner=runner,
        config=A2aAgentExecutorConfig(
            request_converter=convert_a2a_request_to_agent_sse_run_request
        ),
    )

    request_handler = DefaultRequestHandler(
        agent_executor=agent_executor, task_store=InMemoryTaskStore()
    )

    # Create a Starlette app that will be configured during startup
    app = Starlette()

    async def setup_a2a():
        final_agent_card = await card_builder.build()

        # Create the A2A Starlette application
        a2a_app = A2AStarletteApplication(
            agent_card=final_agent_card,
            http_handler=request_handler,
        )

        # Add A2A routes to the main app
        a2a_app.add_routes_to_app(
            app,
        )

    # Store the setup function to be called during startup
    app.add_event_handler("startup", setup_a2a)

    return app


async def run_agent():
    _ = await runner.session_service.create_session(
        user_id="test_user", session_id="test_session", app_name="remote_agent"
    )
    async for event in runner.run_async(
        user_id="test_user",
        session_id="test_session",
        new_message=types.Content(
            role="user",
            parts=[types.Part(text="Tell me a joke.")],
        ),
        run_config=RunConfig(streaming_mode=StreamingMode.SSE),
    ):
        if event.partial:
            print(f"Event.partial={event.partial} | Content='{event.content.parts[0].text}'")

    print(event.content.parts[0].text)


if __name__ == "__main__":
    import asyncio

    import uvicorn

    a2a_app = asyncio.run(get_app())

    # Run the agent locally, here we see that partial events are marked as partial=True
    asyncio.run(run_agent())

    # Then run the app to expose the agent remotely
    uvicorn.run(a2a_app, host="0.0.0.0", port=8001)

Client setup

To setup a client interacting with the remote A2A agent, it is enough to provide an a2a_client_factory configured with streaming enabled. Running the script below will show that the SSE events from the remote agent are correctly received, but have Event.partial=None.

from uuid import uuid4

from a2a.client.client import ClientConfig as A2AClientConfig
from a2a.client.client_factory import ClientFactory as A2AClientFactory
from a2a.types import TransportProtocol as A2ATransport
from google.adk.agents.remote_a2a_agent import (
    AGENT_CARD_WELL_KNOWN_PATH,
    RemoteA2aAgent,
)
from google.adk.agents.run_config import RunConfig, StreamingMode
from google.adk.runners import Runner
from google.adk.sessions.in_memory_session_service import InMemorySessionService
from google.genai import types

# Configure the client factory to support streaming
client_config = A2AClientConfig(
    streaming=True,
    polling=False,
    supported_transports=[A2ATransport.jsonrpc],
)
a2a_client_factory = A2AClientFactory(config=client_config)


root_agent = RemoteA2aAgent(
    name="client_agent",
    description=("An agent that tells jokes and stories."),
    agent_card=f"http://localhost:8001/{AGENT_CARD_WELL_KNOWN_PATH}",
    a2a_client_factory=a2a_client_factory,
)

runner = Runner(
    app_name="client_agent",
    agent=root_agent,
    session_service=InMemorySessionService(),
)


async def run_agent():
    user_id, session_id = str(uuid4()), str(uuid4())

    _ = await runner.session_service.create_session(
        user_id=user_id, session_id=session_id, app_name="client_agent"
    )
    async for event in runner.run_async(
        user_id=user_id,
        session_id=session_id,
        new_message=types.Content(
            role="user",
            parts=[types.Part(text="Tell me a joke.")],
        ),
        run_config=RunConfig(streaming_mode=StreamingMode.SSE),
    ):
        if event.partial:
            print("Partial stream:", event.content.parts[0].text)
        else:
            # All partial events from the remote agent have been sent with partial=None
            print(f"Event.partial={event.partial} | Content='{event.content.parts[0].text}'")

    print("Final content:\n" + event.content.parts[0].text)


if __name__ == "__main__":
    import asyncio

    asyncio.run(run_agent())

seandi avatar Nov 10 '25 18:11 seandi

Event.partial is lost because it's not in the optional_fields list in _get_context_metadata (event_converter.py:137-144) and not reconstructed in convert_a2a_message_to_event (event_converter.py:343-358).

The fix is straightforward - add ("partial", event.partial) to optional_fields and extract it during reverse conversion, following the same pattern as long_running_tool_ids (lines 178-197, 317-329).

This is consistent with how Event.actions was just added in v1.21.0 (commit 32e87f63).

The issue still exists in v1.21.0.

Additionally, RemoteA2aAgent has streaming=False hardcoded at line 206, which prevents SSE streaming even when remote agents support it - you'll need to pass a custom a2a_client_factory with streaming=True as you've done.

surajksharma07 avatar Dec 14 '25 18:12 surajksharma07

@seanzhou1023 Please have a look into it.

surajksharma07 avatar Dec 14 '25 18:12 surajksharma07

Checked against latest ADK (post v1.23.0) — both issues are still present.

Event.partial is still missing from the optional_fields list in _get_context_metadata() at event_converter.py:138-145, so it's lost during A2A conversion.

And RemoteA2aAgent still has streaming=False hardcoded at remote_a2a_agent.py:212 with no way to configure it.

The workaround of passing a custom a2a_client_factory with streaming=True still applies.

surajksharma07 avatar Feb 04 '26 12:02 surajksharma07

It looks like this was resolved in v1.27.0: https://github.com/google/adk-python/commit/87ffc55640dea1185cf67e6f9b78f70b30867bcc

rmoneys avatar Apr 15 '26 22:04 rmoneys

Thanks @rmoneys for tracking that down!

Confirmed — commit 87ffc55 (shipped in v1.27.0) resolves both issues reported here.

The new from_adk_event.py / a2a_agent_executor_impl.py implementation explicitly reads event.partial and maps it to last_chunk=not partial / append=partial on TaskArtifactUpdateEvent, so partial streaming state is now correctly propagated across A2A boundaries.

The workaround of passing a custom a2a_client_factory with streaming=True is no longer needed either — the new executor handles streaming natively.

surajksharma07 avatar Apr 16 '26 03:04 surajksharma07