Skip to content

Commit dc13e48

Browse files
committed
agentic to async
1 parent 1808d4e commit dc13e48

File tree

30 files changed

+205
-185
lines changed

30 files changed

+205
-185
lines changed

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
Tests for ab000-hello-acp (agentic agent)
2+
Tests for ab000-hello-acp (async agent)
33
4-
This test suite demonstrates testing an agentic agent using the AgentEx testing framework.
4+
This test suite demonstrates testing an async agent using the AgentEx testing framework.
55
66
Test coverage:
77
- Event sending and polling for responses
@@ -16,11 +16,15 @@
1616
pytest tests/test_agent.py -v
1717
"""
1818

19+
import asyncio
1920
import pytest
2021
import pytest_asyncio
2122

23+
from agentex.lib.testing.sessions import AsyncAgentTest
24+
from agentex.lib.testing import stream_agent_response
25+
2226
from agentex.lib.testing import (
23-
test_agentic_agent,
27+
async_test_agent,
2428
assert_valid_agent_response,
2529
assert_agent_response_contains,
2630
)
@@ -32,30 +36,28 @@ def agent_name():
3236
"""Return the agent name for testing."""
3337
return AGENT_NAME
3438

39+
3540
@pytest_asyncio.fixture
3641
async def test_agent(agent_name: str):
37-
"""Fixture to create a test agentic agent."""
38-
async with test_agentic_agent(agent_name=agent_name) as test:
42+
"""Fixture to create a test async agent."""
43+
async with async_test_agent(agent_name=agent_name) as test:
3944
yield test
4045

4146

4247
class TestNonStreamingEvents:
4348
"""Test non-streaming event sending and polling."""
4449

4550
@pytest.mark.asyncio
46-
async def test_send_event_and_poll(self, agent_name):
51+
async def test_send_event_and_poll(self, test_agent: AsyncAgentTest):
4752
"""Test sending an event and polling for the response."""
48-
async with test_agentic_agent(agent_name=agent_name) as test:
49-
# First event - should get initial task creation message
50-
initial_response = await test.send_event("Start task", timeout_seconds=30.0)
51-
assert_valid_agent_response(initial_response)
52-
assert_agent_response_contains(initial_response, "Hello! I've received your task")
53-
54-
# Second event - send user message
55-
user_message = "Hello, this is a test message!"
56-
response = await test.send_event(user_message, timeout_seconds=30.0)
57-
58-
# Validate response
53+
# Poll for initial task creation message
54+
initial_response = await test_agent.poll_for_agent_response(timeout_seconds=15.0)
55+
assert_valid_agent_response(initial_response)
56+
assert_agent_response_contains(initial_response, "Hello! I've received your task")
57+
58+
# Send a test message and validate response
59+
response = await test_agent.send_event("Hello, this is a test message!", timeout_seconds=30.0)
60+
# Validate latest response
5961
assert_valid_agent_response(response)
6062
assert_agent_response_contains(response, "Hello! I've received your message")
6163

@@ -64,7 +66,7 @@ class TestStreamingEvents:
6466
"""Test streaming event sending."""
6567

6668
@pytest.mark.asyncio
67-
async def test_send_event_and_stream(self, test_agent):
69+
async def test_send_event_and_stream(self, test_agent: AsyncAgentTest):
6870
"""Test sending an event and streaming the response."""
6971
user_message = "Hello, this is a test message!"
7072

@@ -75,7 +77,8 @@ async def test_send_event_and_stream(self, test_agent):
7577
all_events = []
7678

7779
# Stream events
78-
async for event in test_agent.send_event_and_stream(user_message, timeout_seconds=30.0):
80+
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):
7982
all_events.append(event)
8083
event_type = event.get("type")
8184

@@ -98,11 +101,17 @@ async def test_send_event_and_stream(self, test_agent):
98101
user_echo_found = True
99102

100103
# Exit early if we've found expected messages
101-
if task_creation_found and agent_response_found:
104+
if task_creation_found and agent_response_found and user_echo_found:
102105
break
103106

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)
104110
# Validate we saw expected messages
105-
assert task_creation_found or agent_response_found, "Did not receive agent messages"
111+
assert task_creation_found, "Did not receive task creation message"
112+
assert agent_response_found, "Did not receive agent response to user message"
113+
# User echo is optional; no assert
114+
assert user_echo_found, "User echo message not found"
106115
assert len(all_events) > 0, "Should receive events"
107116

108117

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
Tests for ab010-multiturn (agentic agent)
2+
Tests for ab010-multiturn (async agent)
33
4-
This test suite demonstrates testing a multi-turn agentic agent using the AgentEx testing framework.
4+
This test suite demonstrates testing a multi-turn async agent using the AgentEx testing framework.
55
66
Test coverage:
77
- Multi-turn event sending with state management
@@ -21,7 +21,7 @@
2121

2222
from agentex import AsyncAgentex
2323
from agentex.lib.testing import (
24-
test_agentic_agent,
24+
async_test_agent,
2525
assert_valid_agent_response,
2626
)
2727

@@ -39,7 +39,7 @@ async def test_multiturn_with_state_management():
3939
agent = next((a for a in agents if a.name == AGENT_NAME), None)
4040
assert agent is not None, f"Agent {AGENT_NAME} not found"
4141

42-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
42+
async with async_test_agent(agent_name=AGENT_NAME) as test:
4343
# Wait for state initialization
4444
await asyncio.sleep(1)
4545

@@ -77,7 +77,7 @@ async def test_multiturn_with_state_management():
7777

7878
@pytest.mark.asyncio
7979
async def test_streaming_events():
80-
"""Test streaming events from agentic agent."""
80+
"""Test streaming events from async agent."""
8181
# Need client access to check state
8282
client = AsyncAgentex(api_key="test", base_url="http://localhost:5003")
8383

@@ -86,7 +86,7 @@ async def test_streaming_events():
8686
agent = next((a for a in agents if a.name == AGENT_NAME), None)
8787
assert agent is not None, f"Agent {AGENT_NAME} not found"
8888

89-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
89+
async with async_test_agent(agent_name=AGENT_NAME) as test:
9090
# Wait for state initialization
9191
await asyncio.sleep(1)
9292

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Tests for ab020-streaming (agentic agent)
2+
Tests for ab020-streaming (async agent)
33
44
Test coverage:
55
- Event sending and polling
@@ -18,7 +18,7 @@
1818
from agentex import AsyncAgentex
1919
from agentex.lib.testing import (
2020
assert_valid_agent_response,
21-
test_agentic_agent,
21+
async_test_agent,
2222
)
2323

2424
AGENT_NAME = "ab020-streaming"
@@ -35,7 +35,7 @@ async def test_send_event_and_poll():
3535
agent = next((a for a in agents if a.name == AGENT_NAME), None)
3636
assert agent is not None, f"Agent {AGENT_NAME} not found"
3737

38-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
38+
async with async_test_agent(agent_name=AGENT_NAME) as test:
3939
# Wait for state initialization
4040
await asyncio.sleep(1)
4141

@@ -80,7 +80,7 @@ async def test_streaming_events():
8080
agent = next((a for a in agents if a.name == AGENT_NAME), None)
8181
assert agent is not None, f"Agent {AGENT_NAME} not found"
8282

83-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
83+
async with async_test_agent(agent_name=AGENT_NAME) as test:
8484
# Wait for state initialization
8585
await asyncio.sleep(1)
8686

examples/tutorials/10_async/00_base/030_tracing/tests/test_agent.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
Tests for ab030-tracing (agentic agent)
2+
Tests for ab030-tracing (async agent)
33
4-
This test suite demonstrates testing an agentic agent with tracing enabled.
4+
This test suite demonstrates testing an async agent with tracing enabled.
55
66
Test coverage:
77
- Basic event sending and polling
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020
from agentex.lib.testing import (
21-
test_agentic_agent,
21+
async_test_agent,
2222
)
2323

2424
AGENT_NAME = "ab030-tracing"
@@ -27,7 +27,7 @@
2727
@pytest.mark.asyncio
2828
async def test_basic_event():
2929
"""Test sending an event and receiving a response."""
30-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
30+
async with async_test_agent(agent_name=AGENT_NAME) as test:
3131
response = await test.send_event("Hello! Test message", timeout_seconds=30.0)
3232
# Agent may return empty response depending on configuration
3333
assert response is not None
@@ -38,7 +38,7 @@ async def test_basic_event():
3838
@pytest.mark.asyncio
3939
async def test_streaming_event():
4040
"""Test streaming events from agent."""
41-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
41+
async with async_test_agent(agent_name=AGENT_NAME) as test:
4242
events_received = []
4343

4444
async for event in test.send_event_and_stream("Stream this", timeout_seconds=30.0):

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313

1414
from agentex import AsyncAgentex
15-
from agentex.lib.testing import test_agentic_agent, assert_valid_agent_response
15+
from agentex.lib.testing import async_test_agent, assert_valid_agent_response
1616

1717
AGENT_NAME = "ab040-other-sdks"
1818

@@ -28,7 +28,7 @@ async def test_agent_basic():
2828
agent = next((a for a in agents if a.name == AGENT_NAME), None)
2929
assert agent is not None, f"Agent {AGENT_NAME} not found"
3030

31-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
31+
async with async_test_agent(agent_name=AGENT_NAME) as test:
3232
# Wait for state initialization
3333
await asyncio.sleep(1)
3434

@@ -65,7 +65,7 @@ async def test_poll_with_tool_use():
6565
agent = next((a for a in agents if a.name == AGENT_NAME), None)
6666
assert agent is not None, f"Agent {AGENT_NAME} not found"
6767

68-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
68+
async with async_test_agent(agent_name=AGENT_NAME) as test:
6969
# Wait for state initialization
7070
await asyncio.sleep(1)
7171

@@ -113,7 +113,7 @@ async def test_poll_multiturn():
113113
agent = next((a for a in agents if a.name == AGENT_NAME), None)
114114
assert agent is not None, f"Agent {AGENT_NAME} not found"
115115

116-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
116+
async with async_test_agent(agent_name=AGENT_NAME) as test:
117117
# Wait for state initialization
118118
await asyncio.sleep(1)
119119

@@ -153,7 +153,7 @@ async def test_basic_streaming():
153153
agent = next((a for a in agents if a.name == AGENT_NAME), None)
154154
assert agent is not None, f"Agent {AGENT_NAME} not found"
155155

156-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
156+
async with async_test_agent(agent_name=AGENT_NAME) as test:
157157
# Wait for state initialization
158158
await asyncio.sleep(1)
159159

@@ -218,7 +218,7 @@ async def test_streaming_with_tools():
218218
agent = next((a for a in agents if a.name == AGENT_NAME), None)
219219
assert agent is not None, f"Agent {AGENT_NAME} not found"
220220

221-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
221+
async with async_test_agent(agent_name=AGENT_NAME) as test:
222222
# Wait for state initialization
223223
await asyncio.sleep(1)
224224

examples/tutorials/10_async/00_base/080_batch_events/tests/test_agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import re
1515

1616
from agentex import AsyncAgentex
17-
from agentex.lib.testing import test_agentic_agent, assert_valid_agent_response, stream_agent_response
17+
from agentex.lib.testing import async_test_agent, assert_valid_agent_response, stream_agent_response
1818
from agentex.types.text_content_param import TextContentParam
1919
from agentex.types.task_message_content import TextContent
2020

@@ -24,7 +24,7 @@
2424
@pytest.mark.asyncio
2525
async def test_single_event_and_poll():
2626
"""Test sending a single event and polling for response."""
27-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
27+
async with async_test_agent(agent_name=AGENT_NAME) as test:
2828
response = await test.send_event("Process this single event", timeout_seconds=30.0)
2929
assert_valid_agent_response(response)
3030
assert "Processed event IDs" in response.content
@@ -41,7 +41,7 @@ async def test_batch_events_and_poll():
4141
assert agent is not None, f"Agent {AGENT_NAME} not found"
4242

4343
num_events = 7
44-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
44+
async with async_test_agent(agent_name=AGENT_NAME) as test:
4545
for i in range(num_events):
4646
event_content = TextContentParam(type="text", author="user", content=f"Batch event {i + 1}")
4747
await client.agents.send_event(agent_id=agent.id, params={"task_id": test.task_id, "content": event_content})
@@ -91,7 +91,7 @@ async def test_batched_streaming():
9191
assert agent is not None, f"Agent {AGENT_NAME} not found"
9292

9393
num_events = 10
94-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
94+
async with async_test_agent(agent_name=AGENT_NAME) as test:
9595
for i in range(num_events):
9696
event_content = TextContentParam(type="text", author="user", content=f"Batch event {i + 1}")
9797
await client.agents.send_event(agent_id=agent.id, params={"task_id": test.task_id, "content": event_content})

examples/tutorials/10_async/00_base/090_multi_agent_non_temporal/tests/test_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010

1111
import pytest
1212

13-
from agentex.lib.testing import test_agentic_agent, assert_valid_agent_response
13+
from agentex.lib.testing import async_test_agent, assert_valid_agent_response
1414

1515
AGENT_NAME = "ab090-orchestrator-agent"
1616

1717

1818
@pytest.mark.asyncio
1919
async def test_agent_basic():
2020
"""Test basic agent functionality."""
21-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
21+
async with async_test_agent(agent_name=AGENT_NAME) as test:
2222
response = await test.send_event("Test message", timeout_seconds=30.0)
2323
assert_valid_agent_response(response)
2424

2525

2626
@pytest.mark.asyncio
2727
async def test_agent_streaming():
2828
"""Test streaming responses."""
29-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
29+
async with async_test_agent(agent_name=AGENT_NAME) as test:
3030
events = []
3131
async for event in test.send_event_and_stream("Stream test", timeout_seconds=30.0):
3232
events.append(event)

examples/tutorials/10_async/10_temporal/000_hello_acp/tests/test_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111

1212
import pytest
1313

14-
from agentex.lib.testing import test_agentic_agent, assert_valid_agent_response
14+
from agentex.lib.testing import async_test_agent, assert_valid_agent_response
1515

1616
AGENT_NAME = "at000-hello-acp"
1717

1818

1919
@pytest.mark.asyncio
2020
async def test_agent_basic():
2121
"""Test basic agent functionality."""
22-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
22+
async with async_test_agent(agent_name=AGENT_NAME) as test:
2323
response = await test.send_event("Test message", timeout_seconds=60.0)
2424
assert_valid_agent_response(response)
2525

2626

2727
@pytest.mark.asyncio
2828
async def test_agent_streaming():
2929
"""Test streaming responses."""
30-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
30+
async with async_test_agent(agent_name=AGENT_NAME) as test:
3131
events = []
3232
async for event in test.send_event_and_stream("Stream test", timeout_seconds=60.0):
3333
events.append(event)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717

1818
import pytest
1919

20-
from agentex.lib.testing import test_agentic_agent, assert_valid_agent_response
20+
from agentex.lib.testing import async_test_agent, assert_valid_agent_response
2121

2222
AGENT_NAME = "at010-agent-chat"
2323

2424

2525
@pytest.mark.asyncio
2626
async def test_agent_basic():
2727
"""Test basic agent functionality."""
28-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
28+
async with async_test_agent(agent_name=AGENT_NAME) as test:
2929
response = await test.send_event("Test message", timeout_seconds=60.0)
3030
assert_valid_agent_response(response)
3131

3232

3333
@pytest.mark.asyncio
3434
async def test_agent_streaming():
3535
"""Test streaming responses."""
36-
async with test_agentic_agent(agent_name=AGENT_NAME) as test:
36+
async with async_test_agent(agent_name=AGENT_NAME) as test:
3737
events = []
3838
async for event in test.send_event_and_stream("Stream test", timeout_seconds=60.0):
3939
events.append(event)

0 commit comments

Comments
 (0)