Skip to content

Commit 82ed9c8

Browse files
committed
Update test_agent.py
1 parent dc13e48 commit 82ed9c8

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

  • examples/tutorials/10_async/00_base/000_hello_acp/tests

examples/tutorials/10_async/00_base/000_hello_acp/tests/test_agent.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
pytest tests/test_agent.py -v
1717
"""
1818

19-
import asyncio
2019
import pytest
2120
import pytest_asyncio
2221

@@ -71,46 +70,39 @@ async def test_send_event_and_stream(self, test_agent: AsyncAgentTest):
7170
user_message = "Hello, this is a test message!"
7271

7372
# Flags to track what we've received
74-
task_creation_found = False
7573
user_echo_found = False
7674
agent_response_found = False
7775
all_events = []
7876

7977
# Stream events
8078
async for event in stream_agent_response(test_agent.client, test_agent.task_id, timeout=30.0):
81-
#async for event in test_agent.send_event_and_stream(user_message, timeout_seconds=30.0):
8279
all_events.append(event)
8380
event_type = event.get("type")
8481

85-
if event_type == "full":
82+
if event_type == 'connected':
83+
await test_agent.send_event(user_message, timeout_seconds=30.0)
84+
85+
elif event_type == "full":
8686
content = event.get("content", {})
8787
if content.get("content") is None:
8888
continue # Skip empty content
8989

9090
if content.get("type") == "text" and content.get("author") == "agent":
91-
# Check for initial task creation message
92-
if "Hello! I've received your task" in content.get("content", ""):
93-
task_creation_found = True
9491
# Check for agent response to user message
95-
elif "Hello! I've received your message" in content.get("content", ""):
92+
if "Hello! I've received your message" in content.get("content", ""):
9693
agent_response_found = True
94+
assert user_echo_found, "User echo should be found before agent response"
9795

9896
elif content.get("type") == "text" and content.get("author") == "user":
9997
# Check for user message echo (may or may not be present)
10098
if content.get("content") == user_message:
10199
user_echo_found = True
102100

103101
# Exit early if we've found expected messages
104-
if task_creation_found and agent_response_found and user_echo_found:
102+
if agent_response_found and user_echo_found:
105103
break
106104

107-
print('all events', all_events)
108-
messages = await test_agent.client.messages.list(task_id=test_agent.task_id)
109-
print('all messages', messages)
110-
# Validate we saw expected messages
111-
assert task_creation_found, "Did not receive task creation message"
112105
assert agent_response_found, "Did not receive agent response to user message"
113-
# User echo is optional; no assert
114106
assert user_echo_found, "User echo message not found"
115107
assert len(all_events) > 0, "Should receive events"
116108

0 commit comments

Comments
 (0)