Skip to content

Commit

Permalink
automatically add log entries corresponding to scene boundaries.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 635883960
Change-Id: I0a35e34abe925d7e304bb48a4dfe5adefc6b69aa
  • Loading branch information
jzleibo authored and copybara-github committed May 21, 2024
1 parent 0c70e9c commit 1ca47be
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions concordia/environment/game_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from collections.abc import Callable, Sequence
import concurrent.futures
import dataclasses
import datetime
import random

from concordia import components as generic_components
Expand Down Expand Up @@ -55,6 +57,20 @@
)


@dataclasses.dataclass
class LogEntry:
"""A log entry to be inserted into the game master's log at a given time.
Attributes:
date: the time associated with this log entry (in-game time)
event_statement: a statement of the event that occurred
summary: information about the event
"""
date: datetime.datetime
event_statement: str
summary: str


class GameMaster(simulacrum_game_master.GameMaster):
"""A generic game master."""

Expand Down Expand Up @@ -158,6 +174,15 @@ def name(self) -> str:
def get_history(self):
return self._log.copy()

def insert_history(self, log_entry: LogEntry):
"""Insert a log entry into the game master's log, often used with scenes."""
update_log = {
'date': log_entry.date,
'Event statement': log_entry.event_statement,
'Summary': log_entry.summary,
}
self._log.append(update_log)

def get_memory(self) -> associative_memory.AssociativeMemory:
return self._memory

Expand Down
11 changes: 11 additions & 0 deletions concordia/environment/scenes/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,29 @@ def run_scenes(

# Prepare to run the scene
clock.set(scene.start_time)

all_premises = ''
for participant in participants:
premise_messages = _get_interscene_messages(
key='premise',
agent_name=participant.name,
scene_type_spec=scene.scene_type,
)
for message in premise_messages:
all_premises += f'{participant.name} -- premise: {message} \n'
if verbose:
print(f'{participant.name} -- premise: {message}')
participant.observe(message)
this_scene_game_master_memory.add(message)

# Add the scene and its premise to the history
scene_update_log_entry = game_master.LogEntry(
date=clock.now(),
event_statement=all_premises,
summary=f'Scene {scene_idx} --- Participants: {participant_names}',
)
environment.insert_history(log_entry=scene_update_log_entry)

# Run the scene
for _ in range(scene.num_rounds):
this_scene_game_master_memory.add(f'[scene type] {scene.scene_type.name}')
Expand Down

0 comments on commit 1ca47be

Please sign in to comment.