Skip to content

Commit 19080e9

Browse files
committed
adding the new image
1 parent e1cc8ae commit 19080e9

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

examples/tutorials/10_async/10_temporal/010_agent_chat/tests/test_agent.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def test_multi_turn_conversation(self, client: AsyncAgentex, agent_id: str
156156
agent_id=agent_id,
157157
task_id=task.id,
158158
user_message=user_message_1,
159-
timeout=20,
159+
timeout=30,
160160
sleep_interval=1.0,
161161
):
162162
assert isinstance(message, TaskMessage)
@@ -215,14 +215,16 @@ async def test_send_event_and_stream_with_reasoning(self, client: AsyncAgentex,
215215
# Check for user message and agent response
216216
user_message_found = False
217217
agent_response_found = False
218+
reasoning_found = False
218219

219220
async def stream_messages() -> None: # noqa: ANN101
220-
nonlocal user_message_found, agent_response_found
221+
nonlocal user_message_found, agent_response_found, reasoning_found
221222
async for event in stream_agent_response(
222223
client=client,
223224
task_id=task.id,
224-
timeout=60,
225+
timeout=90, # Increased timeout for CI environments
225226
):
227+
print(event)
226228
msg_type = event.get("type")
227229
if msg_type == "full":
228230
task_message_update = StreamTaskMessageFull.model_validate(event)
@@ -241,22 +243,40 @@ async def stream_messages() -> None: # noqa: ANN101
241243
):
242244
agent_response_found = True
243245
elif finished_message.content and finished_message.content.type == "reasoning":
244-
tool_response_found = True
246+
reasoning_found = True
247+
248+
# Exit early if we have what we need
249+
if user_message_found and agent_response_found:
250+
break
251+
245252
elif msg_type == "done":
246253
task_message_update = StreamTaskMessageDone.model_validate(event)
247254
if task_message_update.parent_task_message and task_message_update.parent_task_message.id:
248255
finished_message = await client.messages.retrieve(task_message_update.parent_task_message.id)
249256
if finished_message.content and finished_message.content.type == "reasoning":
257+
reasoning_found = True
258+
elif (
259+
finished_message.content
260+
and finished_message.content.type == "text"
261+
and finished_message.content.author == "agent"
262+
):
250263
agent_response_found = True
251-
continue
264+
265+
# Exit early if we have what we need
266+
if user_message_found and agent_response_found:
267+
break
252268

253269
stream_task = asyncio.create_task(stream_messages())
254270

255271
event_content = TextContentParam(type="text", author="user", content=user_message)
256272
await client.agents.send_event(agent_id=agent_id, params={"task_id": task.id, "content": event_content})
257273

258-
# Wait for streaming to complete
259-
await stream_task
274+
# Wait for streaming to complete with timeout
275+
try:
276+
await asyncio.wait_for(stream_task, timeout=120) # Overall timeout for CI
277+
except asyncio.TimeoutError:
278+
stream_task.cancel()
279+
pytest.fail("Test timed out waiting for streaming response")
260280

261281
assert user_message_found, "User message not found in stream"
262282
assert agent_response_found, "Agent response not found in stream"

examples/tutorials/test_utils/async_utils.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,10 @@ async def poll_messages(
125125

126126
if yield_updates:
127127
# For streaming: track content changes
128-
content_str = message.content.content if message.content and hasattr(message.content, 'content') else ""
129-
# Ensure content_str is always a string to avoid concatenation errors
130-
if isinstance(content_str, list):
131-
# If it's a list, convert to string representation
132-
content_str = str(content_str)
133-
elif content_str is None:
134-
content_str = ""
135-
elif not isinstance(content_str, str):
136-
# Handle any other non-string types
137-
content_str = str(content_str)
128+
# Use getattr to safely extract content and convert to string
129+
# This handles various content structures at runtime
130+
raw_content = getattr(message.content, 'content', message.content) if message.content else None
131+
content_str = str(raw_content) if raw_content is not None else ""
138132

139133
# Ensure streaming_status is also properly converted to string
140134
streaming_status_str = str(message.streaming_status) if message.streaming_status is not None else ""

0 commit comments

Comments
 (0)