Skip to content

Commit 5e851c5

Browse files
committed
remove legacy code, fix voted out message
1 parent dafbefb commit 5e851c5

11 files changed

Lines changed: 20 additions & 273 deletions

File tree

scripts/main.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

scripts/random_game.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import os
1111
import argparse
1212

13-
def main(reset=False, always_kill=False, remove_last_n=0):
13+
def main(reset=False, greedy=False, remove_last_n=0):
1414
"""Runs the game with manual LLM control."""
1515
game_config = GameConfig(
1616
num_tasks=2,
@@ -83,11 +83,11 @@ def main(reset=False, always_kill=False, remove_last_n=0):
8383
# Here, you would insert your custom LLM call and log probability logic.
8484
action_taken = random.choice(actions_player_can_take)
8585
kill_actions = [action for action in actions_player_can_take if action.type == ActionType.KILL]
86-
task_actions = [action for action in actions_player_can_take if action.type == ActionType.TASK]
87-
if current_player.role == PlayerRole.IMPOSTOR and kill_actions and always_kill:
86+
task_or_report_actions = [action for action in actions_player_can_take if action.type == ActionType.TASK or action.type == ActionType.REPORT]
87+
if current_player.role == PlayerRole.IMPOSTOR and kill_actions and greedy:
8888
action_taken = random.choice(kill_actions)
89-
elif current_player.role == PlayerRole.CREWMATE and task_actions:
90-
action_taken = random.choice(task_actions)
89+
elif current_player.role == PlayerRole.CREWMATE and task_or_report_actions and greedy:
90+
action_taken = random.choice(task_or_report_actions)
9191
llm_response, cot = action_taken.command_perspective, "<think>Was thinking about this option: " + action_taken.command_perspective + "</think>"
9292
except KeyboardInterrupt:
9393
action_idx, llm_response, cot, _ = prompt_manual_fallback_action(actions_player_can_take)
@@ -118,13 +118,13 @@ def parse_args():
118118
parser = argparse.ArgumentParser(description="Run Among Them game with custom options.")
119119
parser.add_argument("--reset", action="store_true",
120120
help="Remove the state file and start a new game")
121-
parser.add_argument("--always-kill", action="store_true",
122-
help="Impostors will always choose to kill when possible")
123-
parser.add_argument("--remove-last-n", type=int, default=0,
121+
parser.add_argument("--greedy", action="store_true",
122+
help="Impostors will always choose to kill when possible and crewmates will always choose to task/report when possible")
123+
parser.add_argument("-n", type=int, default=0,
124124
help="Remove the last N entries from history and start from there")
125125
return parser.parse_args()
126126

127127

128128
if __name__ == "__main__":
129129
args = parse_args()
130-
main(reset=args.reset, always_kill=args.always_kill, remove_last_n=args.remove_last_n)
130+
main(reset=args.reset, greedy=args.greedy, remove_last_n=args.n)

scripts/streamlit.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,6 @@ def load_game_state(file_path, last_modified_time) -> Tuple[List[History], List[
331331
task_complete = game_config.num_tasks - len(tasks)
332332
task_total = game_config.num_tasks
333333

334-
# Count completed tasks
335-
for task in tasks:
336-
if hasattr(task, 'completed') and task.completed:
337-
task_complete += 1
338-
339334
# Show progress bar
340335
st.progress(task_complete / task_total)
341336
st.write(f"{task_complete}/{task_total} tasks completed")
@@ -344,14 +339,13 @@ def load_game_state(file_path, last_modified_time) -> Tuple[List[History], List[
344339
for task in tasks:
345340
task_name = task.name if hasattr(task, 'name') else str(task)
346341
task_location = task.location.value if hasattr(task, 'location') and task.location else "Unknown"
347-
task_status = "✅" if hasattr(task, 'completed') and task.completed else "⏳"
348342

349343
# If it's a long task, show turns left
350344
turns_info = ""
351345
if hasattr(task, 'turns_left'):
352346
turns_info = f" ({task.turns_left} turns left)"
353347

354-
st.write(f"{task_status} {task_name} at {task_location}{turns_info}")
348+
st.write(f"TODO: {task_name} at {task_location}{turns_info}")
355349

356350
with tabs[3]: # Player Network
357351
st.header("Player Interaction Network")

src/among_them/game_engine.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import random
33
from typing import List, Optional
4-
import copy
54

65
from among_them.config import STATE_FILE
76
from among_them.game_jsonencoder import GameJSONEncoder, game_object_hook

src/among_them/main.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/among_them/models/action.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ def set_stories(self):
4343
self.command_perspective = f"report the dead body of {str(self.target_player_name)}"
4444
self.agent_perspective = f"You reported the dead body of {str(self.target_player_name)} and started a discussion."
4545
self.observer_perspective = f"You saw {self.player_name} report the dead body of {str(self.target_player_name)} to everyone. Discussion started."
46-
self.global_perspective = f"A dead body was reported by {self.player_name}. Discussion started."
46+
self.global_perspective = f"{self.player_name} reported the dead body of {str(self.target_player_name)}. Discussion started."
4747
elif self.type == ActionType.KILL:
4848
self.command_perspective = f"kill {str(self.target_player_name)}"
4949
self.agent_perspective = f"You killed {str(self.target_player_name)}."
5050
self.observer_perspective = f"You witnessed {self.player_name} kill {str(self.target_player_name)}!"
51-
self.global_perspective = f"{str(self.target_player_name)} was killed."
51+
self.global_perspective = f"{self.player_name} killed {str(self.target_player_name)}."
52+
if getattr(self, "target_message", None) and self.player_name == "System":
53+
self.agent_perspective = f"System said: {self.target_message}"
54+
self.observer_perspective = f"System said: {self.target_message}"
55+
self.global_perspective = f"System said: {self.target_message}"
5256
elif self.type == ActionType.VOTE:
5357
self.command_perspective = f"vote for {str(self.target_player_name)}"
5458
self.agent_perspective = f"You voted for {str(self.target_player_name)}."

src/among_them/models/tasks.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from enum import Enum
21
import random
32
from typing import Optional
43

@@ -7,21 +6,12 @@
76

87

98
class Task:
10-
def __init__(self, name: str, location: Optional[Location], completed: bool = False):
9+
def __init__(self, name: str, location: Optional[Location]):
1110
self.name = name
12-
self.completed = completed
1311
self.location = location
1412

15-
def complete(self, location: Location) -> str:
16-
if self.completed:
17-
return f"Task {self.name} already completed!"
18-
if self.location != location:
19-
return f"Task {self.name} cannot be completed in {location.value}!"
20-
self.completed = True
21-
return f"Task {self.name} completed!"
22-
2313
def __str__(self):
24-
return f"{'[DONE]' if self.completed else '[TODO]'} | {self.name}"
14+
return f"TODO: {self.name}"
2515

2616
def __repr__(self):
2717
return self.name

src/among_them/utils/action_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_task_phase_actions(
4949

5050
# actions for tasks TASK
5151
for task in history[-1].tasks_left_to_do[player.name]:
52-
if player.role == PlayerRole.CREWMATE and task.location == location and not task.completed:
52+
if player.role == PlayerRole.CREWMATE and task.location == location:
5353
actions.append(
5454
Action(type=ActionType.TASK, player_name=player.name, target_task=task)
5555
)
Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from typing import List, Optional
2+
from typing import List
33
from among_them.models.player import Player
44
from among_them.game_config import GameConfig
55
from among_them.models.history import History
@@ -9,7 +9,6 @@
99
from among_them.models.action_type import ActionType
1010
from among_them.models.phase import GamePhase
1111
from among_them.models.tasks import get_impostor_tasks, get_crewmate_tasks
12-
from among_them.utils.player_utils import get_players_in_room, get_last_player_action
1312

1413
def initialize_history(players: List[Player], game_config: GameConfig) -> List[History]:
1514
"""Create first history entry – a system message that the game started (TASK phase)."""
@@ -72,94 +71,3 @@ def create_system_message(
7271
votes_before_this_discussion_message={},
7372
alive_player_names=alive_player_names.copy(),
7473
)
75-
76-
def get_action_history_str(history: List[History], players: List[Player], player: Player, game_config: GameConfig, phase: Optional[GamePhase] = None) -> str:
77-
"""
78-
DEPRECATED: see prompt_utils.py
79-
Returns all actions seen by agent and actions that agent saw/spectated in history in order.
80-
"""
81-
phase = history[-1].phase
82-
players_in_room = get_players_in_room(history, players, player)
83-
alive_players = [p for p in players if p.name in history[-1].alive_player_names]
84-
location = get_last_player_action(history, player).location
85-
86-
# Agent description
87-
history_str = "<player_info>\n"
88-
history_str += f"<player_name>{player.name}</player_name>\n<current_role>{player.role.value}</current_role>\n<current_location>{location.value}</current_location>\n"
89-
other_impostors = [p for p in alive_players if p.role == PlayerRole.IMPOSTOR and p.name != player.name]
90-
if player.role == PlayerRole.IMPOSTOR:
91-
other_crewmates = [p for p in alive_players if p.role == PlayerRole.CREWMATE and p.name != player.name]
92-
if other_impostors:
93-
history_str += "<other_impostors>\n"
94-
for imp in other_impostors:
95-
history_str += f"<impostor>{imp.name}</impostor>\n"
96-
history_str += "</other_impostors>\n"
97-
else:
98-
history_str += "<other_impostors>none</other_impostors>\n"
99-
100-
if other_crewmates:
101-
history_str += "<crewmates>\n"
102-
for crew in other_crewmates:
103-
history_str += f"<crewmate>{crew.name}</crewmate>\n"
104-
history_str += "</crewmates>\n"
105-
else:
106-
other_players = [p.name for p in alive_players if p.name != player.name]
107-
history_str += f"<impostor_count>{len(other_impostors)}</impostor_count>\n"
108-
history_str += "<potential_impostors>\n"
109-
for other_player in other_players:
110-
history_str += f"<player>{other_player}</player>\n"
111-
history_str += "</potential_impostors>\n"
112-
113-
# Tasks left
114-
tasks_left = []
115-
for h in history:
116-
if player.name in h.tasks_left_to_do:
117-
tasks_left = h.tasks_left_to_do[player.name]
118-
break
119-
120-
if tasks_left:
121-
history_str += "<tasks_left>\n"
122-
for task in tasks_left:
123-
history_str += f"<task><name>{task.name}</name><location>{task.location.value if task.location else 'N/A'}</location></task>\n"
124-
history_str += "</tasks_left>\n"
125-
history_str += "</player_info>\n\n"
126-
127-
# Game history
128-
history_str += "<game_history>\n"
129-
for h in history:
130-
if h.action_taken:
131-
if h.action_taken.player_name == player.name:
132-
if hasattr(h, 'llm_cot') and h.llm_cot:
133-
cot_without_think_tags = h.llm_cot.replace("<think>", "<thought>").replace("</think>", "</thought>")
134-
history_str += f"<player_thought>{cot_without_think_tags}</player_thought>\n"
135-
if h.action_taken.type == ActionType.SPEAK:
136-
history_str += f"<action type=\"player_message\">{h.action_taken.agent_perspective}</action>\n"
137-
else:
138-
history_str += f"<action type=\"player_action\">{h.action_taken.agent_perspective}</action>\n"
139-
elif player.name in h.spectators_who_saw:
140-
if h.action_taken.type == ActionType.SPEAK:
141-
history_str += f"<action type=\"discussion\">{h.action_taken.observer_perspective}</action>\n"
142-
elif h.action_taken.type != ActionType.VOTE: # players cannot see others voting
143-
history_str += f"<action type=\"observed\">{h.action_taken.observer_perspective}</action>\n"
144-
history_str += "</game_history>\n\n"
145-
146-
# Current game state
147-
history_str += "<current_state>\n"
148-
other_players = [p.name for p in players_in_room if p.name != player.name]
149-
if phase == GamePhase.TASKS:
150-
if len(other_players) == 0:
151-
history_str += "<companions>none</companions>\n"
152-
history_str += f"<location>{location.value}</location>\n"
153-
else:
154-
history_str += "<companions>\n"
155-
for other_player in other_players:
156-
history_str += f"<player>{other_player}</player>\n"
157-
history_str += "</companions>\n"
158-
history_str += f"<location>{location.value}</location>\n"
159-
history_str += "<phase>Task</phase>\n<note>You cannot speak during this phase.</note>\n"
160-
elif phase == GamePhase.VOTING:
161-
history_str += "<phase>Voting</phase>\n"
162-
else:
163-
history_str += "<phase>Discussion</phase>\n<note>You can speak now. Respond to the crewmates.</note>\n"
164-
history_str += "</current_state>\n"
165-
return history_str

src/among_them/utils/llm_utils.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,9 @@
22
from typing import List, Optional, Tuple
33

44
from among_them.config import LLMBackend, LLM_BACKEND, OPENROUTER_API_KEY, OPENROUTER_MODEL_NAME, HUGGINGFACE_MODEL_NAME
5-
from among_them.llm_prompts import UNIVERSAL_SYSTEM_PROMPT
65
from among_them.models.action import Action, ActionType
76

87

9-
def create_llm_prompts(actions: List[Action], history_str: str) -> Tuple[str, str]:
10-
"""Constructs the prompt for the LLM.
11-
Args:
12-
actions: List of available actions
13-
history_str: String representation of game history
14-
Returns:
15-
Tuple of (system_prompt, user_prompt)
16-
"""
17-
system_prompt = UNIVERSAL_SYSTEM_PROMPT
18-
prompt = history_str
19-
20-
# Add available actions to prompt if needed
21-
if actions and actions[0].type != ActionType.SPEAK:
22-
actions_text = "<available_actions>\n" + "\n".join(f"<action>{action.text}</action>" for action in actions) + "\n</available_actions>"
23-
prompt += f"\n\n{actions_text}\n"
24-
if actions[0].type == ActionType.VOTE:
25-
prompt += "\n\nChoose one action. Please put your final answer within <action></action> xml tags"
26-
else:
27-
prompt += "\n\nChoose one action. Please put your final vote within <action></action> xml tags"
28-
elif actions and actions[0].type == ActionType.SPEAK:
29-
prompt += "\n\nIt is discussion phase now. Respond to others. Please put your message between <message></message> xml tags"
30-
31-
return system_prompt, prompt
32-
33-
348
def invoke_llm(system_prompt: str, prompt: str, model_name: str) -> Tuple[str, Optional[str]]:
359
"""
3610
Invoke the LLM with the given prompts and handle exceptions.
@@ -193,7 +167,6 @@ def parse_llm_response_to_action(
193167
"""
194168
Parses the raw LLM response to determine the chosen action index and response text.
195169
"""
196-
from among_them.models.action import ActionType
197170

198171
if not actions:
199172
raise ValueError("Cannot parse LLM response without a list of available actions.")

0 commit comments

Comments
 (0)