@@ -265,68 +265,115 @@ def choose_observation_location(self, map):
265265
266266
267267class HumanAgent (Agent ):
268- def __init__ (self , player ):
268+ def __init__ (self , player , tools = None , game_index = 0 , agent_config = None , list_of_impostors = None ):
269269 super ().__init__ (player )
270-
271- def choose_action (self ):
272- print (f"{ str (self .player )} " )
273-
270+ self .model = "homosapiens/brain-1.0"
271+ self .tools = tools
272+ self .game_index = game_index
273+ self .summarization = "No thought process has been made."
274+ self .processed_memory = "No memory has been processed."
275+ self .log_path = os .getenv ("EXPERIMENT_PATH" ) + "/agent-logs.json"
276+ self .compact_log_path = os .getenv ("EXPERIMENT_PATH" ) + "/agent-logs-compact.json"
277+
278+ # Initialize global session state if it doesn't exist
279+ if os .getenv ("FLASK" ) == "True" :
280+ # Global session state for actions across page refreshes
281+ if "human_actions" not in st .session_state :
282+ st .session_state .human_actions = {}
283+ if "action_history" not in st .session_state :
284+ st .session_state .action_history = {}
285+ if "game_started" not in st .session_state :
286+ st .session_state .game_started = False
287+
288+ async def choose_action (self , timestep ):
289+ all_info = self .player .all_info_prompt ()
274290 available_actions = self .player .get_available_actions ()
275- print (self .player .all_info_prompt ())
291+
292+ # Log the start of action selection
293+ action_prompt = f"Available actions:\n " + "\n " .join ([f"{ i + 1 } : { action } " for i , action in enumerate (available_actions )])
294+ full_prompt = {
295+ "All Info" : all_info ,
296+ "Available Actions" : action_prompt
297+ }
298+ # Command line interface
299+ print (f"{ str (self .player )} " )
300+ print (all_info )
301+ print ("Choose an action:" )
302+ for i , action in enumerate (available_actions ):
303+ print (f"{ i + 1 } : { action } " )
304+
276305 stop_triggered = False
277306 valid_input = False
278307 while (not stop_triggered ) and (not valid_input ):
279- print ("Choose an action:" )
280308 try :
281309 action_idx = int (input ())
282310 if action_idx == 0 :
283311 stop_triggered = True
284312 elif action_idx < 1 or action_idx > len (available_actions ):
285- raise ValueError (
286- f"Invalid input. Please enter a number between 1 and { len (available_actions )} ."
287- )
313+ raise ValueError (f"Invalid input. Please enter a number between 1 and { len (available_actions )} ." )
288314 else :
289315 valid_input = True
290-
291316 except :
292317 print ("Invalid input. Please enter a number." )
293318 continue
319+
294320 if stop_triggered :
295321 raise ValueError ("Game stopped by user." )
296- action = available_actions [action_idx - 1 ]
297- if action .name == "SPEAK" :
298- message = self .speak ()
299- action .provide_message (message )
300- if action .name == "SPEAK" :
301- action .provide_message (message )
302- return action
322+
323+ selected_action = available_actions [action_idx - 1 ]
324+
325+ if selected_action .name == "SPEAK" :
326+ print ("Enter your response:" )
327+ action_message = input ()
328+ selected_action .provide_message (action_message )
329+ self .log_interaction (sysprompt = "Human Agent" , prompt = full_prompt ,
330+ original_response = f"[Action] { selected_action } with message: { action_message } " ,
331+ step = timestep )
332+ else :
333+ self .log_interaction (sysprompt = "Human Agent" , prompt = full_prompt ,
334+ original_response = f"[Action] { selected_action } " ,
335+ step = timestep )
336+
337+ return selected_action
303338
304339 def respond (self , message ):
305340 print (message )
306341 response = input ()
307342 return response
308343
309- def speak (self ):
310- print ("Enter your response:" )
311- message = input ()
312- return message
313-
314344 def choose_observation_location (self , map ):
315- map = list (map )
316- print ("Please select the room you wish to observe:" )
317- for i , room in enumerate (map ):
318- print (f"{ i } : " + room )
345+ map_list = list (map )
319346 while True :
320- index = int (input ())
321- if index < 0 or index >= len (map ):
322- print (
323- f"Invalid input. Please enter a number between 0 and { len (map ) - 1 } ."
324- )
325- else :
326- print (map )
327- print ("index" , index )
328- print ("map[index]" , map [index ])
329- return map [index ]
347+ try :
348+ index = int (input ())
349+ if index < 0 or index >= len (map_list ):
350+ print (f"Invalid input. Please enter a number between 0 and { len (map_list ) - 1 } ." )
351+ else :
352+ return map_list [index ]
353+ except :
354+ print ("Invalid input. Please enter a number." )
355+
356+ def log_interaction (self , sysprompt , prompt , original_response , step ):
357+ """Log human player interactions similar to LLMAgent"""
358+ interaction = {
359+ 'game_index' : 'Game ' + str (self .game_index ),
360+ 'step' : step ,
361+ "timestamp" : str (datetime .now ()),
362+ "player" : {"name" : self .player .name , "identity" : self .player .identity , "personality" : self .player .personality , "model" : self .model , "location" : self .player .location },
363+ "interaction" : {"system_prompt" : sysprompt , "prompt" : prompt , "response" : original_response , "full_response" : original_response },
364+ }
365+
366+ # Write to file
367+ with open (self .log_path , "a" ) as f :
368+ json .dump (interaction , f , indent = 2 , separators = ("," , ": " ))
369+ f .write ("\n " )
370+ f .flush ()
371+ with open (self .compact_log_path , "a" ) as f :
372+ json .dump (interaction , f , separators = ("," , ": " ))
373+ f .write ("\n " )
374+ f .flush ()
375+
376+ print ("." , end = "" , flush = True )
330377
331378
332379class LLMHumanAgent (HumanAgent , LLMAgent ):
0 commit comments