You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
fix: Prevent stopping event processing on events with None content
PiperOrigin-RevId: 856706510
This commit is contained in:
committed by
Copybara-Service
parent
50c4b8d33a
commit
ed2c3ebde9
@@ -348,6 +348,13 @@ class RemoteA2aAgent(BaseAgent):
|
||||
|
||||
return a2a_message
|
||||
|
||||
def _is_remote_response(self, event: Event) -> bool:
|
||||
return (
|
||||
event.author == self.name
|
||||
and event.custom_metadata
|
||||
and event.custom_metadata.get(A2A_METADATA_PREFIX + "response", False)
|
||||
)
|
||||
|
||||
def _construct_message_parts_from_session(
|
||||
self, ctx: InvocationContext
|
||||
) -> tuple[list[A2APart], Optional[str]]:
|
||||
@@ -365,7 +372,7 @@ class RemoteA2aAgent(BaseAgent):
|
||||
|
||||
events_to_process = []
|
||||
for event in reversed(ctx.session.events):
|
||||
if event.author == self.name:
|
||||
if self._is_remote_response(event):
|
||||
# stop on content generated by current a2a agent given it should already
|
||||
# be in remote session
|
||||
if event.custom_metadata:
|
||||
@@ -496,6 +503,8 @@ class RemoteA2aAgent(BaseAgent):
|
||||
invocation_id=ctx.invocation_id,
|
||||
branch=ctx.branch,
|
||||
)
|
||||
event.custom_metadata = event.custom_metadata or {}
|
||||
event.custom_metadata[A2A_METADATA_PREFIX + "response"] = True
|
||||
return event
|
||||
except A2AClientError as e:
|
||||
logger.error("Failed to handle A2A response: %s", e)
|
||||
|
||||
@@ -683,7 +683,16 @@ class TestRemoteA2aAgentMessageHandling:
|
||||
agent1 = Mock()
|
||||
agent1.content = content2
|
||||
agent1.author = self.agent.name
|
||||
agent1.custom_metadata = None
|
||||
agent1.custom_metadata = {
|
||||
A2A_METADATA_PREFIX + "response": True,
|
||||
}
|
||||
|
||||
agent2 = Mock()
|
||||
agent2.content = None
|
||||
agent2.author = self.agent.name
|
||||
# Just actions, no content. Not marked as a response.
|
||||
agent2.actions = Mock()
|
||||
agent2.custom_metadata = None
|
||||
|
||||
part3 = Mock()
|
||||
part3.text = "User 2"
|
||||
@@ -694,7 +703,7 @@ class TestRemoteA2aAgentMessageHandling:
|
||||
user2.author = "user"
|
||||
user2.custom_metadata = None
|
||||
|
||||
self.mock_session.events = [user1, agent1, user2]
|
||||
self.mock_session.events = [user1, agent1, user2, agent2]
|
||||
|
||||
def mock_converter(part):
|
||||
mock_a2a_part = Mock()
|
||||
@@ -785,7 +794,10 @@ class TestRemoteA2aAgentMessageHandling:
|
||||
agent1 = Mock()
|
||||
agent1.content = content2
|
||||
agent1.author = self.agent.name
|
||||
agent1.custom_metadata = {A2A_METADATA_PREFIX + "context_id": "ctx-1"}
|
||||
agent1.custom_metadata = {
|
||||
A2A_METADATA_PREFIX + "response": True,
|
||||
A2A_METADATA_PREFIX + "context_id": "ctx-1",
|
||||
}
|
||||
|
||||
part3 = Mock()
|
||||
part3.text = "User 2"
|
||||
|
||||
Reference in New Issue
Block a user