|
16 | 16 | pytest tests/test_agent.py -v |
17 | 17 | """ |
18 | 18 |
|
| 19 | +import pytest |
| 20 | + |
19 | 21 | from agentex.lib.testing import ( |
20 | 22 | test_sync_agent, |
21 | 23 | collect_streaming_deltas, |
22 | 24 | assert_valid_agent_response, |
23 | | - assert_conversation_maintains_context |
24 | 25 | ) |
25 | 26 |
|
26 | 27 | AGENT_NAME = "s010-multiturn" |
27 | 28 |
|
| 29 | +@pytest.fixture |
| 30 | +def agent_name(): |
| 31 | + """Return the agent name for testing.""" |
| 32 | + return AGENT_NAME |
28 | 33 |
|
29 | | -def test_multiturn_conversation(): |
30 | | - """Test multi-turn conversation with non-streaming messages.""" |
31 | | - with test_sync_agent(agent_name=AGENT_NAME) as test: |
| 34 | +@pytest.fixture |
| 35 | +def test_agent(agent_name: str): |
| 36 | + """Fixture to create a test sync agent.""" |
| 37 | + with test_sync_agent(agent_name=agent_name) as test: |
| 38 | + yield test |
| 39 | + |
| 40 | + |
| 41 | +class TestNonStreamingMessages: |
| 42 | + """Test non-streaming message sending.""" |
| 43 | + |
| 44 | + def test_send_simple_message(self, test_agent): |
32 | 45 | messages = [ |
33 | 46 | "Hello, can you tell me a litle bit about tennis? I want to you make sure you use the word 'tennis' in each response.", |
34 | 47 | "Pick one of the things you just mentioned, and dive deeper into it.", |
35 | 48 | "Can you now output a summary of this conversation", |
36 | 49 | ] |
37 | | - |
38 | | - for msg in messages: |
39 | | - response = test.send_message(msg) |
| 50 | + for i, msg in enumerate(messages): |
| 51 | + response = test_agent.send_message(msg) |
40 | 52 |
|
41 | 53 | # Validate response (agent may require OpenAI key) |
42 | 54 | assert_valid_agent_response(response) |
43 | 55 |
|
44 | 56 | # Validate that "tennis" appears in the response because that is what our model does |
45 | 57 | assert "tennis" in response.content.lower() |
46 | 58 |
|
47 | | - # Verify conversation history |
48 | | - history = test.get_conversation_history() |
49 | | - assert len(history) >= 6, f"Expected >= 6 messages (3 user + 3 agent), got {len(history)}" |
| 59 | + # Verify conversation history |
| 60 | + message_history = test_agent.get_conversation_history() |
| 61 | + assert len(message_history) == (i + 1) * 2 # user + agent messages |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +def test_multiturn_conversation(): |
| 66 | + """Test multi-turn conversation with non-streaming messages.""" |
| 67 | + with test_sync_agent(agent_name=AGENT_NAME) as test: |
| 68 | + |
| 69 | + |
| 70 | + |
50 | 71 |
|
51 | 72 |
|
52 | 73 | def test_multiturn_streaming(): |
|
0 commit comments