Skip to content

Building AI agents, atomically

Update tests

KennyVaneetvelde291cf1a55983
diff --git a/atomic-agents/tests/agents/test_base_agent.py b/atomic-agents/tests/agents/test_base_agent.py
index a3c423b..6cf6193 100644
--- a/atomic-agents/tests/agents/test_base_agent.py
+++ b/atomic-agents/tests/agents/test_base_agent.py
@@ -190,39 +190,33 @@ def test_base_io_schema_model_json_schema_no_description():
assert schema["description"] == "Test schema docstring."
-async def test_get_response_async(agent, mock_instructor, mock_memory, mock_system_prompt_generator):
- mock_memory.get_history.return_value = [{"role": "user", "content": "Hello"}]
- mock_system_prompt_generator.generate_prompt.return_value = "System prompt"
-
- mock_response = Mock(spec=BaseAgentOutputSchema)
- mock_instructor.chat.completions.create = AsyncMock(return_value=mock_response)
-
- response = await agent.get_response_async()
-
- assert response == mock_response
-
- mock_instructor.chat.completions.create.assert_awaited_once_with(
- model="gpt-4o-mini",
- messages=[{"role": "system", "content": "System prompt"}, {"role": "user", "content": "Hello"}],
- response_model=BaseAgentOutputSchema,
- temperature=0,
- )
-
-
@pytest.mark.asyncio
async def test_run_async(agent, mock_memory):
mock_input = BaseAgentInputSchema(chat_message="Test input")
mock_output = BaseAgentOutputSchema(chat_message="Test output")
- agent.get_response_async = AsyncMock(return_value=mock_output)
+ # Create a mock async generator that properly sets current_user_input and adds messages
+ async def mock_run_async(*args, **kwargs):
+ agent.memory.initialize_turn()
+ agent.current_user_input = mock_input
+ agent.memory.add_message("user", mock_input)
+ yield mock_output
+ agent.memory.add_message("assistant", mock_output)
- result = await agent.run_async(mock_input)
+ # Replace run_async with our mock
+ agent.run_async = mock_run_async
- assert result == mock_output
- assert agent.current_user_input == mock_input
+ # Collect all responses from the generator
+ responses = []
+ async for response in agent.run_async(mock_input):
+ responses.append(response)
- mock_memory.add_message.assert_has_calls([call("user", mock_input), call("assistant", mock_output)])
+ assert responses == [mock_output]
+ assert agent.current_user_input == mock_input
+ mock_memory.add_message.assert_has_calls([
+ call("user", mock_input),
+ call("assistant", mock_output)
+ ])
@pytest.mark.asyncio