Skip to content

Commit

Permalink
Creating independent agents, and adding an action suggester (#33)
Browse files Browse the repository at this point in the history
* ✨ feat(scenario_agents,-concordia_utils.py,-main.py): separate agents from main code, add ability to save and load agents

* 🐛 fix(voter_agent.py-main.py): fixed issue with saving agents

* ✨ feat(scenario_agents-concordia_utils.py): introduced the action suggester designed by austin and fixed bugs with malicious agent >>> ⏰ 5h

* 🐛 fix(dashboard-basic.py-apps.py): fixed bug with toot_id type

* 🐛 fix(dashbaord-basic.py): added ep -1 to viw

* 🐛 fix(dashboard-basic.py): added check for first name only agent label error and toot_id type as int error. also fixed display to show episode=-1 >>> ⏰ 1h (#22) (#26)

changes here are to make the dashboard display correct and complete

Co-authored-by: Maximilian Puelma Touzel <max.puelmatouzel@gmail.com>

* ⚡️ perf(scene.py-basic_malicious_agent.py): improve post frequency

* ✨ feat(agent-files): added chain of thought before action decision

---------

Co-authored-by: Sneheel Sarangi <ss14247@dn339.fast>
Co-authored-by: Sneheel Sarangi <ss14247@dn197.fast>
Co-authored-by: Sneheel Sarangi <ss14247@dn304.fast>
Co-authored-by: Maximilian Puelma Touzel <max.puelmatouzel@gmail.com>
  • Loading branch information
5 people authored Feb 3, 2025
1 parent 9ad2930 commit dc95d2f
Show file tree
Hide file tree
Showing 14 changed files with 2,759 additions and 1,321 deletions.
2 changes: 1 addition & 1 deletion examples/election/notebooks/basic_output_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"id": "4890b769-a2a0-4bdf-87c9-ca1c4ea9b2c3",
"metadata": {},
"outputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def get_int_dict(int_df):
"episode": x.episode,
"source": x.source_user,
"target": get_target_user(x),
"toot_id": x.data["toot_id"],
"toot_id": str(x.data["toot_id"]),
},
axis=1,
)
int_df.int_data = int_df.apply(
lambda x: x.int_data | {"parent_toot_id": x.data["reply_to"]["toot_id"]}
lambda x: x.int_data | {"parent_toot_id": str(x.data["reply_to"]["toot_id"])}
if x.label == "reply"
else x.int_data,
axis=1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

ROOT_PROJ_PATH = os.getenv("ROOT_PROJ_PATH")
if ROOT_PROJ_PATH is not None:
ROOT_PATH = ROOT_PROJ_PATH + "socialsandbox/mastodon-sim/"
ROOT_PATH = ROOT_PROJ_PATH + "mastodon-sim/"
else:
sys.exit("No add absolute path found as environment variable.")

Expand Down
15 changes: 12 additions & 3 deletions examples/election/src/election_sim/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
load_dotenv()
ROOT_PROJ_PATH = os.getenv("ROOT_PROJ_PATH")
if ROOT_PROJ_PATH is not None:
ROOT_PATH = ROOT_PROJ_PATH + "socialsandbox/mastodon-sim/"
ROOT_PATH = ROOT_PROJ_PATH + "mastodon-sim/"
else:
sys.exit("No add absolute path found as environment variable.")

Expand All @@ -109,6 +109,7 @@
SimpleGameRunner,
build_agent_with_memories,
init_concordia_objects,
save_to_json,
sort_agents,
)
from sim_utils.misc_sim_utils import event_logger, post_analysis
Expand Down Expand Up @@ -153,7 +154,7 @@ def add_news_agent_to_mastodon_app(news_agent, action_logger, players, mastodon_
)
# We still need to give the news agent a phone to be able to post toots #TODO we are not sure if we need to do this
# phones[n_agent["name"]] = apps.Phone(n_agent["name"], apps=[mastodon_apps[n_agent["name"].split()[0]]])
user_mapping[n_agent["mastodon_username"]] = f"user{len(players)+1+i:04d}"
user_mapping[n_agent["mastodon_username"]] = f"user{len(players) + 1 + i:04d}"
# set a mapping of display name to user name for news agent
mastodon_apps[n_agent["name"]].set_user_mapping(user_mapping) # e.g., "storhampton_gazette"
mastodon_ops.update_bio(
Expand Down Expand Up @@ -542,6 +543,14 @@ def run_sim(
print(f"Episode: {i}")
eval_event_logger.episode_idx = i
action_event_logger.episode_idx = i
for player in players:
player_dir = os.path.join("output/player_checkpoints", player.name)
os.makedirs(player_dir, exist_ok=True)
file_path = os.path.join(player_dir, f"Episode_{i}.json")
# Get JSON data from player
json_data = save_to_json(player)
with open(file_path, "w") as file:
file.write(json.dumps(json_data, indent=4))
deploy_surveys(players, eval_config, eval_event_logger)

start_timex = time.time()
Expand Down Expand Up @@ -591,7 +600,7 @@ def run_sim(
# experiment_name = "bias"
# experiment_name = "malicious"
experiment_name = args.exp
# N=100
# N = 100
N = 20
# survey = "None.Big5"
# survey = "Costa_et_al_JPersAssess_2021.Schwartz"
Expand Down
Empty file.
Loading

0 comments on commit dc95d2f

Please # to comment.