Skip to content

Commit 9176a31

Browse files
jzleibocopybara-github
authored andcommitted
make clocks optional in unstable basic and example agent factories.
PiperOrigin-RevId: 732531058 Change-Id: Id1d30166aa4dfdb02bed57b9960e93345dba5d79
1 parent 6ffda73 commit 9176a31

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

concordia/factory/agent/unstable/basic.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def build_agent(
4343
config: formative_memories.AgentConfig,
4444
model: language_model.LanguageModel,
4545
memory: basic_associative_memory.AssociativeMemoryBank,
46-
clock: game_clock.MultiIntervalClock,
46+
clock: game_clock.MultiIntervalClock | None = None,
4747
) -> entity_agent_with_logging.EntityAgentWithLogging:
4848
"""Build an agent.
4949
@@ -69,11 +69,16 @@ def build_agent(
6969
logging_channel=measurements.get_channel('Instructions').on_next,
7070
)
7171

72-
time_display = agent_components.report_function.ReportFunction(
73-
function=clock.current_time_interval_str,
74-
pre_act_key='\nCurrent time',
75-
logging_channel=measurements.get_channel('TimeDisplay').on_next,
76-
)
72+
if clock:
73+
clock_now = clock.now
74+
time_display = agent_components.report_function.ReportFunction(
75+
function=clock.current_time_interval_str,
76+
pre_act_key='\nCurrent time',
77+
logging_channel=measurements.get_channel('TimeDisplay').on_next,
78+
)
79+
else:
80+
clock_now = None
81+
time_display = None
7782

7883
observation_to_memory = agent_components_v2.observation.ObservationToMemory(
7984
logging_channel=measurements.get_channel(
@@ -123,7 +128,7 @@ def build_agent(
123128
situation_representation_label
124129
),
125130
},
126-
clock_now=clock.now,
131+
clock_now=clock_now,
127132
pre_act_key=person_by_situation_label,
128133
logging_channel=measurements.get_channel('PersonBySituation').on_next,
129134
)
@@ -156,7 +161,6 @@ def build_agent(
156161

157162
entity_components = (
158163
# Components that provide pre_act context.
159-
time_display,
160164
relevant_memories,
161165
self_perception,
162166
situation_representation,
@@ -171,6 +175,8 @@ def build_agent(
171175
components_of_agent[
172176
agent_components_v2.observation.DEFAULT_OBSERVATION_COMPONENT_NAME
173177
] = observation
178+
if time_display:
179+
components_of_agent['TimeDisplay'] = time_display
174180

175181
component_order = list(components_of_agent.keys())
176182

concordia/factory/agent/unstable/example.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def build_agent(
3535
config: formative_memories.AgentConfig,
3636
model: language_model.LanguageModel,
3737
memory: basic_associative_memory.AssociativeMemoryBank,
38-
clock: game_clock.MultiIntervalClock,
38+
clock: game_clock.MultiIntervalClock | None = None,
3939
) -> entity_agent_with_logging.EntityAgentWithLogging:
4040
"""Build an agent.
4141
@@ -70,6 +70,17 @@ def build_agent(
7070
history_length=100,
7171
)
7272

73+
if clock:
74+
clock_now = clock.now
75+
time_display = agent_components.report_function.ReportFunction(
76+
function=clock.current_time_interval_str,
77+
pre_act_key='\nCurrent time',
78+
logging_channel=measurements.get_channel('TimeDisplay').on_next,
79+
)
80+
else:
81+
clock_now = None
82+
time_display = None
83+
7384
situation_representation = components_unstable.question_of_recent_memories.SituationPerceptionWithoutPreAct(
7485
model=model,
7586
)
@@ -84,7 +95,7 @@ def build_agent(
8495

8596
person_by_situation = components_unstable.question_of_recent_memories.PersonBySituationWithoutPreAct(
8697
model=model,
87-
clock_now=clock.now,
98+
clock_now=clock_now,
8899
)
89100
person_by_situation_key = person_by_situation.get_pre_act_key().format(
90101
agent_name=agent_name)
@@ -112,6 +123,10 @@ def build_agent(
112123
components_unstable.memory.AssociativeMemory(memory_bank=memory)
113124
),
114125
}
126+
127+
if time_display:
128+
components_of_agent['TimeDisplay'] = time_display
129+
115130
choice_of_component_key = 'Choice of component'
116131
components_of_agent[choice_of_component_key] = (
117132
contrib_unstable.choice_of_component.ChoiceOfComponent(

0 commit comments

Comments
 (0)