Skip to content

Commit 31e2305

Browse files
committed
reverting those changes
1 parent 0f0b8b9 commit 31e2305

File tree

10 files changed

+408
-298
lines changed

10 files changed

+408
-298
lines changed

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

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@
1515
- AGENT_NAME: Name of the agent to test (default: ab000-hello-acp)
1616
"""
1717

18+
import asyncio
1819
import os
1920
import uuid
2021

2122
import pytest
2223
import pytest_asyncio
23-
from test_utils.async_utils import (
24-
poll_messages,
25-
stream_agent_response,
26-
send_event_and_poll_yielding,
27-
)
2824

2925
from agentex import AsyncAgentex
3026
from agentex.types import TaskMessage
3127
from agentex.types.agent_rpc_params import ParamsCreateTaskRequest
3228
from agentex.types.text_content_param import TextContentParam
3329

30+
from test_utils.async_utils import (
31+
poll_messages,
32+
send_event_and_poll_yielding,
33+
stream_agent_response,
34+
)
35+
3436
# Configuration from environment variables
3537
AGENTEX_API_BASE_URL = os.environ.get("AGENTEX_API_BASE_URL", "http://localhost:5003")
3638
AGENT_NAME = os.environ.get("AGENT_NAME", "ab000-hello-acp")
@@ -143,36 +145,43 @@ async def test_send_event_and_stream(self, client: AsyncAgentex, agent_id: str):
143145
user_echo_found = False
144146
agent_response_found = False
145147

148+
async def stream_messages() -> None:
149+
nonlocal user_echo_found, agent_response_found
150+
async for event in stream_agent_response(
151+
client=client,
152+
task_id=task.id,
153+
timeout=stream_timeout,
154+
):
155+
all_events.append(event)
156+
# Check events as they arrive
157+
event_type = event.get("type")
158+
if event_type == "full":
159+
content = event.get("content", {})
160+
if content.get("content") is None:
161+
continue # Skip empty content
162+
if content.get("type") == "text" and content.get("author") == "agent":
163+
# Check for agent response to user message
164+
if "Hello! I've received your message" in content.get("content", ""):
165+
# Agent response should come after user echo
166+
assert user_echo_found, "Agent response arrived before user message echo (incorrect order)"
167+
agent_response_found = True
168+
elif content.get("type") == "text" and content.get("author") == "user":
169+
# Check for user message echo
170+
if content.get("content") == user_message:
171+
user_echo_found = True
172+
elif event_type == "done":
173+
break
174+
175+
# Exit early if we've found all expected messages
176+
if user_echo_found and agent_response_found:
177+
break
178+
179+
stream_task = asyncio.create_task(stream_messages())
180+
146181
# Send the event
147182
event_content = TextContentParam(type="text", author="user", content=user_message)
148183
await client.agents.send_event(agent_id=agent_id, params={"task_id": task.id, "content": event_content})
149-
150-
async for event in stream_agent_response(
151-
client=client,
152-
task_id=task.id,
153-
timeout=stream_timeout,
154-
):
155-
all_events.append(event)
156-
# Check events as they arrive
157-
event_type = event.get("type")
158-
if event_type == "full":
159-
content = event.get("content", {})
160-
if content.get("content") is None:
161-
continue # Skip empty content
162-
if content.get("type") == "text" and content.get("author") == "agent":
163-
# Check for agent response to user message
164-
if "Hello! I've received your message" in content.get("content", ""):
165-
# Agent response should come after user echo
166-
assert user_echo_found, "Agent response arrived before user message echo (incorrect order)"
167-
agent_response_found = True
168-
elif content.get("type") == "text" and content.get("author") == "user":
169-
# Check for user message echo
170-
if content.get("content") == user_message:
171-
user_echo_found = True
172-
173-
# Exit early if we've found all expected messages
174-
if user_echo_found and agent_response_found:
175-
break
184+
await stream_task
176185

177186
# Verify all expected messages were received (fail if stream ended without finding them)
178187
assert user_echo_found, "User message echo not found in stream"

examples/tutorials/10_async/00_base/010_multiturn/tests/test_agent.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,31 +167,38 @@ async def test_send_event_and_stream(self, client: AsyncAgentex, agent_id: str):
167167
# Flags to track what we've received
168168
user_message_found = False
169169
agent_response_found = False
170+
async def stream_messages() -> None:
171+
nonlocal user_message_found, agent_response_found
172+
async for event in stream_agent_response(
173+
client=client,
174+
task_id=task.id,
175+
timeout=15,
176+
):
177+
all_events.append(event)
178+
179+
# Check events as they arrive
180+
event_type = event.get("type")
181+
if event_type == "full":
182+
content = event.get("content", {})
183+
if content.get("content") == user_message and content.get("author") == "user":
184+
# User message should come before agent response
185+
assert not agent_response_found, "User message arrived after agent response (incorrect order)"
186+
user_message_found = True
187+
elif content.get("author") == "agent":
188+
# Agent response should come after user message
189+
assert user_message_found, "Agent response arrived before user message (incorrect order)"
190+
agent_response_found = True
191+
elif event_type == "done":
192+
break
193+
194+
# Exit early if we've found both messages
195+
if user_message_found and agent_response_found:
196+
break
197+
198+
stream_task = asyncio.create_task(stream_messages())
170199
event_content = TextContentParam(type="text", author="user", content=user_message)
171200
await client.agents.send_event(agent_id=agent_id, params={"task_id": task.id, "content": event_content})
172-
async for event in stream_agent_response(
173-
client=client,
174-
task_id=task.id,
175-
timeout=15,
176-
):
177-
all_events.append(event)
178-
179-
# Check events as they arrive
180-
event_type = event.get("type")
181-
if event_type == "full":
182-
content = event.get("content", {})
183-
if content.get("content") == user_message and content.get("author") == "user":
184-
# User message should come before agent response
185-
assert not agent_response_found, "User message arrived after agent response (incorrect order)"
186-
user_message_found = True
187-
elif content.get("author") == "agent":
188-
# Agent response should come after user message
189-
assert user_message_found, "Agent response arrived before user message (incorrect order)"
190-
agent_response_found = True
191-
192-
# Exit early if we've found both messages
193-
if user_message_found and agent_response_found:
194-
break
201+
await stream_task
195202

196203
# Validate we received events
197204
assert len(all_events) > 0, "No events received in streaming response"

examples/tutorials/10_async/00_base/020_streaming/tests/test_agent.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,36 @@ async def test_send_event_and_stream(self, client: AsyncAgentex, agent_id: str):
167167
user_message_found = False
168168
full_agent_message_found = False
169169
delta_messages_found = False
170+
async def stream_messages() -> None:
171+
nonlocal user_message_found, full_agent_message_found, delta_messages_found
172+
async for event in stream_agent_response(
173+
client=client,
174+
task_id=task.id,
175+
timeout=15,
176+
):
177+
all_events.append(event)
178+
179+
# Check events as they arrive
180+
event_type = event.get("type")
181+
if event_type == "full":
182+
content = event.get("content", {})
183+
if content.get("content") == user_message and content.get("author") == "user":
184+
user_message_found = True
185+
elif content.get("author") == "agent":
186+
full_agent_message_found = True
187+
elif event_type == "delta":
188+
delta_messages_found = True
189+
elif event_type == "done":
190+
break
191+
192+
# Exit early if we've found all expected messages
193+
if user_message_found and full_agent_message_found and delta_messages_found:
194+
break
195+
196+
stream_task = asyncio.create_task(stream_messages())
170197
event_content = TextContentParam(type="text", author="user", content=user_message)
171198
await client.agents.send_event(agent_id=agent_id, params={"task_id": task.id, "content": event_content})
172-
async for event in stream_agent_response(
173-
client=client,
174-
task_id=task.id,
175-
timeout=15,
176-
):
177-
all_events.append(event)
178-
179-
# Check events as they arrive
180-
event_type = event.get("type")
181-
if event_type == "full":
182-
content = event.get("content", {})
183-
if content.get("content") == user_message and content.get("author") == "user":
184-
user_message_found = True
185-
elif content.get("author") == "agent":
186-
full_agent_message_found = True
187-
elif event_type == "delta":
188-
delta_messages_found = True
189-
190-
# Exit early if we've found all expected messages
191-
if user_message_found and full_agent_message_found and delta_messages_found:
192-
break
199+
await stream_task
193200

194201
# Validate we received events
195202
assert len(all_events) > 0, "No events received in streaming response"

examples/tutorials/10_async/00_base/040_other_sdks/tests/test_agent.py

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,32 @@ async def test_send_event_and_stream_simple(self, client: AsyncAgentex, agent_id
280280
# Collect events from stream
281281
# Check for user message and delta messages
282282
user_message_found = False
283+
async def stream_messages() -> None:
284+
nonlocal user_message_found
285+
async for event in stream_agent_response(
286+
client=client,
287+
task_id=task.id,
288+
timeout=20,
289+
):
290+
msg_type = event.get("type")
291+
# For full messages, content is at the top level
292+
# For delta messages, we need to check parent_task_message
293+
if msg_type == "full":
294+
if (
295+
event.get("content", {}).get("type") == "text"
296+
and event.get("content", {}).get("author") == "user"
297+
):
298+
user_message_found = True
299+
elif msg_type == "done":
300+
break
301+
302+
if user_message_found:
303+
break
304+
305+
stream_task = asyncio.create_task(stream_messages())
283306
event_content = TextContentParam(type="text", author="user", content=user_message)
284307
await client.agents.send_event(agent_id=agent_id, params={"task_id": task.id, "content": event_content})
285-
async for event in stream_agent_response(
286-
client=client,
287-
task_id=task.id,
288-
timeout=20,
289-
):
290-
msg_type = event.get("type")
291-
# For full messages, content is at the top level
292-
# For delta messages, we need to check parent_task_message
293-
if msg_type == "full":
294-
if (
295-
event.get("content", {}).get("type") == "text"
296-
and event.get("content", {}).get("author") == "user"
297-
):
298-
user_message_found = True
299-
elif msg_type == "done":
300-
break
308+
await stream_task
301309
assert user_message_found, "User message found in stream"
302310
## keep polling the states for 10 seconds for the input_list and turn_number to be updated
303311
for i in range(10):
@@ -333,47 +341,51 @@ async def test_send_event_and_stream_with_tools(self, client: AsyncAgentex, agen
333341
tool_requests_seen = []
334342
tool_responses_seen = []
335343
text_deltas_seen = []
344+
async def stream_messages() -> None:
345+
async for event in stream_agent_response(
346+
client=client,
347+
task_id=task.id,
348+
timeout=45,
349+
):
350+
msg_type = event.get("type")
351+
352+
# For full messages, content is at the top level
353+
# For delta messages, we need to check parent_task_message
354+
if msg_type == "delta":
355+
parent_msg = event.get("parent_task_message", {})
356+
content = parent_msg.get("content", {})
357+
delta = event.get("delta", {})
358+
content_type = content.get("type")
359+
360+
if content_type == "text":
361+
text_deltas_seen.append(delta.get("text_delta", ""))
362+
elif msg_type == "full":
363+
# For full messages
364+
content = event.get("content", {})
365+
content_type = content.get("type")
366+
367+
if content_type == "tool_request":
368+
tool_requests_seen.append(
369+
{
370+
"name": content.get("name"),
371+
"tool_call_id": content.get("tool_call_id"),
372+
"streaming_type": msg_type,
373+
}
374+
)
375+
elif content_type == "tool_response":
376+
tool_responses_seen.append(
377+
{
378+
"tool_call_id": content.get("tool_call_id"),
379+
"streaming_type": msg_type,
380+
}
381+
)
382+
elif msg_type == "done":
383+
break
384+
385+
stream_task = asyncio.create_task(stream_messages())
336386
event_content = TextContentParam(type="text", author="user", content=user_message)
337387
await client.agents.send_event(agent_id=agent_id, params={"task_id": task.id, "content": event_content})
338-
async for event in stream_agent_response(
339-
client=client,
340-
task_id=task.id,
341-
timeout=45,
342-
):
343-
msg_type = event.get("type")
344-
345-
# For full messages, content is at the top level
346-
# For delta messages, we need to check parent_task_message
347-
if msg_type == "delta":
348-
parent_msg = event.get("parent_task_message", {})
349-
content = parent_msg.get("content", {})
350-
delta = event.get("delta", {})
351-
content_type = content.get("type")
352-
353-
if content_type == "text":
354-
text_deltas_seen.append(delta.get("text_delta", ""))
355-
elif msg_type == "full":
356-
# For full messages
357-
content = event.get("content", {})
358-
content_type = content.get("type")
359-
360-
if content_type == "tool_request":
361-
tool_requests_seen.append(
362-
{
363-
"name": content.get("name"),
364-
"tool_call_id": content.get("tool_call_id"),
365-
"streaming_type": msg_type,
366-
}
367-
)
368-
elif content_type == "tool_response":
369-
tool_responses_seen.append(
370-
{
371-
"tool_call_id": content.get("tool_call_id"),
372-
"streaming_type": msg_type,
373-
}
374-
)
375-
elif msg_type == "done":
376-
break
388+
await stream_task
377389

378390
# Verify we saw tool usage (if the agent decided to use tools)
379391
# Note: The agent may or may not use tools depending on its reasoning

0 commit comments

Comments
 (0)