@@ -146,3 +146,33 @@ def test_role_playing_with_function():
146146 assert isinstance (response .terminated , bool )
147147 assert response .terminated is False
148148 assert isinstance (response .info , dict )
149+
150+
151+ def test_role_playing_role_sequence (model_type = None ):
152+ task_prompt = "Develop a trading bot for the stock market"
153+ role_playing = RolePlaying (
154+ assistant_role_name = "Python Programmer" ,
155+ assistant_agent_kwargs = dict (model = model_type ),
156+ user_role_name = "Stock Trader" ,
157+ user_agent_kwargs = dict (model = model_type ),
158+ task_prompt = task_prompt ,
159+ with_task_specify = True ,
160+ task_specify_agent_kwargs = dict (model = model_type ),
161+ )
162+ assistant_role_sequence = []
163+ user_role_sequence = []
164+
165+ input_assistant_msg , _ = role_playing .init_chat ()
166+ assistant_response , user_response = role_playing .step (input_assistant_msg )
167+ input_assistant_msg = assistant_response .msg
168+ assistant_response , user_response = role_playing .step (input_assistant_msg )
169+
170+ for record in role_playing .user_agent .stored_messages :
171+ user_role_sequence .append (record .role_at_backend )
172+ for record in role_playing .assistant_agent .stored_messages :
173+ assistant_role_sequence .append (record .role_at_backend )
174+
175+ assert user_role_sequence == \
176+ ['system' , 'user' , 'assistant' , 'user' , 'assistant' ]
177+ assert assistant_role_sequence == \
178+ ['system' , 'user' , 'user' , 'assistant' , 'user' , 'assistant' ]
0 commit comments