Skip to content

Commit da221bb

Browse files
committed
format
1 parent f5acd42 commit da221bb

File tree

29 files changed

+282
-299
lines changed

29 files changed

+282
-299
lines changed

examples/tutorials/00_sync/000_hello_acp/tests/test_agent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
pytest tests/test_agent.py -v
1616
"""
1717

18-
import pytest
18+
import pytest
1919

2020
from agentex.lib.testing import (
2121
test_sync_agent,
@@ -31,6 +31,7 @@ def agent_name():
3131
"""Return the agent name for testing."""
3232
return AGENT_NAME
3333

34+
3435
@pytest.fixture
3536
def test_agent(agent_name: str):
3637
"""Fixture to create a test sync agent."""
@@ -53,6 +54,7 @@ def test_send_simple_message(self, test_agent):
5354
expected = f"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: {message_content}"
5455
assert response.content == expected, f"Expected: {expected}\nGot: {response.content}"
5556

57+
5658
class TestStreamingMessages:
5759
"""Test streaming message sending."""
5860

examples/tutorials/00_sync/010_multiturn/project/acp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ async def handle_message_send(
9090
# Run the agent
9191
result = await Runner.run(test_agent, input_list, run_config=run_config)
9292

93-
9493
# TaskMessages are messages that are sent between an Agent and a Client. They are fundamentally decoupled from messages sent to the LLM. This is because you may want to send additional metadata to allow the client to render the message on the UI differently.
9594

9695
# LLMMessages are OpenAI-compatible messages that are sent to the LLM, and are used to track the state of a conversation with a model.

examples/tutorials/00_sync/010_multiturn/tests/test_agent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

2727
AGENT_NAME = "s010-multiturn"
2828

29+
2930
@pytest.fixture
3031
def agent_name():
3132
"""Return the agent name for testing."""
3233
return AGENT_NAME
3334

35+
3436
@pytest.fixture
3537
def test_agent(agent_name: str):
3638
"""Fixture to create a test sync agent."""
@@ -99,7 +101,7 @@ def test_stream_message(self, test_agent):
99101
assert len(states) == 1
100102

101103
message_history = test_agent.client.messages.list(task_id=test_agent.task_id)
102-
assert len(message_history) == (i + 1) * 2 # user + agent messages
104+
assert len(message_history) == (i + 1) * 2 # user + agent messages
103105

104106

105107
if __name__ == "__main__":

examples/tutorials/00_sync/020_streaming/project/acp.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ async def handle_message_send(
6969

7070
task_messages = await adk.messages.list(task_id=params.task.id)
7171

72-
7372
# Initialize the provider and run config to allow for tracing
7473
provider = SyncStreamingProvider(
7574
trace_id=params.task.id,
@@ -80,7 +79,6 @@ async def handle_message_send(
8079
model_provider=provider,
8180
)
8281

83-
8482
test_agent = Agent(name="assistant", instructions=state.system_prompt, model=state.model)
8583

8684
# Convert task messages to OpenAI Agents SDK format
@@ -89,7 +87,6 @@ async def handle_message_send(
8987
# Run the agent and stream the events
9088
result = Runner.run_streamed(test_agent, input_list, run_config=run_config)
9189

92-
9390
#########################################################
9491
# 4. Stream the events to the client.
9592
#########################################################
@@ -100,4 +97,3 @@ async def handle_message_send(
10097
# Yield the Agentex events to the client
10198
async for agentex_event in convert_openai_to_agentex_events(stream):
10299
yield agentex_event
103-

examples/tutorials/00_sync/020_streaming/tests/test_agent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import pytest
1818

19-
from agentex import Agentex
2019
from agentex.lib.testing import (
2120
test_sync_agent,
2221
collect_streaming_deltas,
@@ -31,12 +30,14 @@ def agent_name():
3130
"""Return the agent name for testing."""
3231
return AGENT_NAME
3332

33+
3434
@pytest.fixture
3535
def test_agent(agent_name: str):
3636
"""Fixture to create a test sync agent."""
3737
with test_sync_agent(agent_name=agent_name) as test:
3838
yield test
3939

40+
4041
class TestNonStreamingMessages:
4142
"""Test non-streaming message sending."""
4243

@@ -86,7 +87,7 @@ def test_send_stream_message(self, test_agent):
8687
# Collect the streaming response
8788
aggregated_content, chunks = collect_streaming_deltas(response_gen)
8889

89-
# this is using the chat_completion_stream, so we will be getting chunks of data
90+
# this is using the chat_completion_stream, so we will be getting chunks of data
9091
assert len(chunks) > 1, "No chunks received in streaming response."
9192

9293
# Validate we got content
@@ -102,7 +103,7 @@ def test_send_stream_message(self, test_agent):
102103
assert state.state is not None
103104
assert state.state.get("system_prompt") == "You are a helpful assistant that can answer questions."
104105
message_history = test_agent.client.messages.list(task_id=test_agent.task_id)
105-
assert len(message_history) == (i + 1) * 2 # user + agent messages
106+
assert len(message_history) == (i + 1) * 2 # user + agent messages
106107

107108

108109
if __name__ == "__main__":

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
import pytest
2020
import pytest_asyncio
2121

22-
from agentex.lib.testing.sessions import AsyncAgentTest
23-
from agentex.lib.testing import stream_agent_response
24-
2522
from agentex.lib.testing import (
2623
async_test_agent,
24+
stream_agent_response,
2725
assert_valid_agent_response,
2826
assert_agent_response_contains,
2927
)
28+
from agentex.lib.testing.sessions import AsyncAgentTest
3029

3130
AGENT_NAME = "ab000-hello-acp"
3231

32+
3333
@pytest.fixture
3434
def agent_name():
3535
"""Return the agent name for testing."""
@@ -79,7 +79,7 @@ async def test_send_event_and_stream(self, test_agent: AsyncAgentTest):
7979
all_events.append(event)
8080
event_type = event.get("type")
8181

82-
if event_type == 'connected':
82+
if event_type == "connected":
8383
await test_agent.send_event(user_message, timeout_seconds=30.0)
8484

8585
elif event_type == "full":

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
"""
1717

1818
import asyncio
19+
1920
import pytest
2021
import pytest_asyncio
2122

22-
from agentex.lib.testing.sessions import AsyncAgentTest
23-
from agentex.lib.testing import stream_agent_response
24-
2523
from agentex.lib.testing import (
2624
async_test_agent,
25+
stream_agent_response,
2726
assert_valid_agent_response,
28-
assert_agent_response_contains,
2927
)
28+
from agentex.lib.testing.sessions import AsyncAgentTest
3029

3130
AGENT_NAME = "ab010-multiturn"
3231

32+
3333
@pytest.fixture
3434
def agent_name():
3535
"""Return the agent name for testing."""
@@ -76,7 +76,7 @@ async def test_send_event_and_poll(self, test_agent: AsyncAgentTest):
7676
state = states[0].state
7777
messages = state.get("messages", [])
7878
assert isinstance(messages, list)
79-
assert len(messages) == 3
79+
assert len(messages) == 3
8080

8181

8282
class TestStreamingEvents:
@@ -114,7 +114,7 @@ async def test_streaming_events(self, test_agent: AsyncAgentTest):
114114
events_received.append(event)
115115
event_type = event.get("type")
116116

117-
if event_type == 'connected':
117+
if event_type == "connected":
118118
await test_agent.send_event(user_message, timeout_seconds=30.0)
119119

120120
elif event_type == "done":
@@ -144,8 +144,8 @@ async def test_streaming_events(self, test_agent: AsyncAgentTest):
144144
assert user_echo_found, "Should receive user message event"
145145

146146
# Verify state has been updated
147-
await asyncio.sleep(1) # Wait for state update
148-
147+
await asyncio.sleep(1) # Wait for state update
148+
149149
states = await test_agent.client.states.list(agent_id=test_agent.agent.id, task_id=test_agent.task_id)
150150
assert len(states) == 1
151151
state = states[0].state

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111
1212
Run: pytest tests/test_agent.py -v
1313
"""
14+
1415
import asyncio
16+
1517
import pytest
1618
import pytest_asyncio
1719

18-
from agentex.lib.testing.sessions import AsyncAgentTest
19-
from agentex.lib.testing import stream_agent_response
20-
2120
from agentex.lib.testing import (
2221
async_test_agent,
22+
stream_agent_response,
2323
assert_valid_agent_response,
2424
)
25+
from agentex.lib.testing.sessions import AsyncAgentTest
2526

2627
AGENT_NAME = "ab020-streaming"
2728

29+
2830
@pytest.fixture
2931
def agent_name():
3032
"""Return the agent name for testing."""
@@ -71,7 +73,7 @@ async def test_send_event_and_poll(self, test_agent: AsyncAgentTest):
7173
state = states[0].state
7274
messages = state.get("messages", [])
7375
assert isinstance(messages, list)
74-
assert len(messages) == 3
76+
assert len(messages) == 3
7577

7678

7779
class TestStreamingEvents:
@@ -110,7 +112,7 @@ async def test_streaming_events(self, test_agent: AsyncAgentTest):
110112
events_received.append(event)
111113
event_type = event.get("type")
112114

113-
if event_type == 'connected':
115+
if event_type == "connected":
114116
await test_agent.send_event(user_message, timeout_seconds=30.0)
115117

116118
elif event_type == "done":
@@ -144,8 +146,8 @@ async def test_streaming_events(self, test_agent: AsyncAgentTest):
144146
assert delta_messages_found, "Should receive delta streaming events"
145147

146148
# Verify state has been updated
147-
await asyncio.sleep(1) # Wait for state update
148-
149+
await asyncio.sleep(1) # Wait for state update
150+
149151
states = await test_agent.client.states.list(agent_id=test_agent.agent.id, task_id=test_agent.task_id)
150152
assert len(states) == 1
151153
state = states[0].state

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515
pytest tests/test_agent.py -v
1616
"""
1717

18-
import asyncio
1918
import pytest
2019
import pytest_asyncio
2120

22-
from agentex.lib.testing.sessions import AsyncAgentTest
23-
from agentex.lib.testing import stream_agent_response
24-
2521
from agentex.lib.testing import (
2622
async_test_agent,
2723
assert_valid_agent_response,
2824
)
29-
25+
from agentex.lib.testing.sessions import AsyncAgentTest
3026

3127
AGENT_NAME = "ab030-tracing"
3228

29+
3330
@pytest.fixture
3431
def agent_name():
3532
"""Return the agent name for testing."""
@@ -61,9 +58,9 @@ async def test_send_event_and_poll(self, test_agent: AsyncAgentTest):
6158
traces = await test_agent.client.spans.list(trace_id=test_agent.task_id)
6259
assert len(traces) > 0, "Should have traces after sending event"
6360
traces_by_name = {trace.name: trace for trace in traces}
64-
assert 'Turn 1' in traces_by_name, "Should have turn-based trace"
65-
assert 'chat_completion_stream_auto_send' in traces_by_name, "Should have chat completion trace"
66-
assert 'update_state' in traces_by_name, "Should have state update trace"
61+
assert "Turn 1" in traces_by_name, "Should have turn-based trace"
62+
assert "chat_completion_stream_auto_send" in traces_by_name, "Should have chat completion trace"
63+
assert "update_state" in traces_by_name, "Should have state update trace"
6764

6865

6966
class TestStreamingEvents:
@@ -101,9 +98,9 @@ async def test_streaming_event(self, test_agent: AsyncAgentTest):
10198
traces = await test_agent.client.spans.list(trace_id=test_agent.task_id)
10299
assert len(traces) > 0, "Should have traces after sending event"
103100
traces_by_name = {trace.name: trace for trace in traces}
104-
assert 'Turn 1' in traces_by_name, "Should have turn-based trace"
105-
assert 'chat_completion_stream_auto_send' in traces_by_name, "Should have chat completion trace"
106-
assert 'update_state' in traces_by_name, "Should have state update trace"
101+
assert "Turn 1" in traces_by_name, "Should have turn-based trace"
102+
assert "chat_completion_stream_auto_send" in traces_by_name, "Should have chat completion trace"
103+
assert "update_state" in traces_by_name, "Should have state update trace"
107104

108105

109106
if __name__ == "__main__":

0 commit comments

Comments
 (0)