feat: emit a TaskStatusUpdateEvent for ADK events with no output parts but with event.actions
PiperOrigin-RevId: 896929519
This commit is contained in:
committed by
Copybara-Service
parent
b0715d77a2
commit
dcc485b23e
@@ -218,6 +218,23 @@ def convert_event_to_a2a_events(
|
||||
),
|
||||
)
|
||||
)
|
||||
elif _serialize_value(event.actions) is not None:
|
||||
a2a_events.append(
|
||||
TaskStatusUpdateEvent(
|
||||
task_id=task_id,
|
||||
context_id=context_id,
|
||||
status=TaskStatus(
|
||||
state=TaskState.working,
|
||||
message=Message(
|
||||
message_id=str(uuid.uuid4()),
|
||||
role=Role.agent,
|
||||
parts=[],
|
||||
),
|
||||
timestamp=datetime.now(timezone.utc).isoformat(),
|
||||
),
|
||||
final=False,
|
||||
)
|
||||
)
|
||||
|
||||
a2a_events = _add_event_metadata(event, a2a_events)
|
||||
return a2a_events
|
||||
@@ -280,7 +297,10 @@ def _add_event_metadata(
|
||||
metadata[_get_adk_metadata_key(field_name)] = value
|
||||
|
||||
for a2a_event in a2a_events:
|
||||
if isinstance(a2a_event, TaskStatusUpdateEvent):
|
||||
if (
|
||||
isinstance(a2a_event, TaskStatusUpdateEvent)
|
||||
and a2a_event.status.message
|
||||
):
|
||||
a2a_event.status.message.metadata = metadata.copy()
|
||||
elif isinstance(a2a_event, TaskArtifactUpdateEvent):
|
||||
a2a_event.artifact.metadata = metadata.copy()
|
||||
|
||||
@@ -21,6 +21,7 @@ from a2a.types import TaskState
|
||||
from a2a.types import TextPart
|
||||
from google.adk.agents.remote_a2a_agent import A2A_METADATA_PREFIX
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.events.event_actions import EventActions
|
||||
from google.adk.platform import uuid as platform_uuid
|
||||
from google.adk.runners import Runner
|
||||
from google.adk.sessions.in_memory_session_service import InMemorySessionService
|
||||
@@ -47,6 +48,11 @@ def create_streaming_mock_run_async(received_requests: list):
|
||||
content=types.Content(parts=[types.Part(text=" world")]),
|
||||
partial=True,
|
||||
)
|
||||
yield Event(
|
||||
author="FakeAgent",
|
||||
partial=True,
|
||||
actions=EventActions(artifact_delta={"file1": 1}),
|
||||
)
|
||||
yield Event(
|
||||
author="FakeAgent",
|
||||
content=types.Content(parts=[types.Part(text="Hello world")]),
|
||||
@@ -92,6 +98,7 @@ async def test_streaming_adk_to_streaming_a2a():
|
||||
new_message = types.Content(parts=[types.Part(text="Hi")], role="user")
|
||||
|
||||
texts = []
|
||||
actions = []
|
||||
async for event in client_runner.run_async(
|
||||
user_id="test_user", session_id="test_session", new_message=new_message
|
||||
):
|
||||
@@ -99,11 +106,15 @@ async def test_streaming_adk_to_streaming_a2a():
|
||||
for p in event.content.parts:
|
||||
if p.text:
|
||||
texts.append(p.text)
|
||||
if event.actions and event.actions.artifact_delta:
|
||||
actions.append(event.actions)
|
||||
|
||||
assert len(received_requests) == 1
|
||||
assert received_requests[0]["session_id"] is not None
|
||||
|
||||
assert texts == ["Hello", " world", "Hello world"]
|
||||
assert len(actions) == 1
|
||||
assert actions[0].artifact_delta == {"file1": 1}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user