Skip to content

Commit a81e65d

Browse files
jzleibocopybara-github
authored andcommitted
Entities can now be passed a custom Measurements object.
Preserves behavior in default case where no measurements object is passed in (creates a standard Measurements object). PiperOrigin-RevId: 879629151 Change-Id: I385a1734986c89f6c3ef8c2391c9bd28e6cec648
1 parent 40b1399 commit a81e65d

23 files changed

+46
-7
lines changed

concordia/agents/entity_agent_with_logging.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(
3838
context_components: Mapping[str, entity_component.ContextComponent] = (
3939
types.MappingProxyType({})
4040
),
41+
measurements: measurements_lib.Measurements | None = None,
4142
):
4243
"""Initializes the agent.
4344
@@ -54,28 +55,42 @@ def __init__(
5455
context_processor: The component that will be used to process contexts. If
5556
None, a NoOpContextProcessor will be used.
5657
context_components: The ContextComponents that will be used by the agent.
58+
measurements: Optional measurements instance to use for logging. Defaults
59+
to a standard Measurements().
5760
"""
5861
super().__init__(agent_name=agent_name,
5962
act_component=act_component,
6063
context_processor=context_processor,
6164
context_components=context_components)
62-
self._component_logging = measurements_lib.Measurements()
65+
self._component_logging = (
66+
measurements
67+
if measurements is not None
68+
else measurements_lib.Measurements()
69+
)
6370

6471
for component_name, component in self._context_components.items():
6572
if isinstance(component, entity_component.ComponentWithLogging):
6673
channel_name = component_name
6774
component.set_logging_channel(
68-
self._component_logging.get_channel(channel_name).append
75+
lambda datum, ch=channel_name: self._component_logging.publish_datum(
76+
ch, datum
77+
)
6978
)
7079
if isinstance(act_component, entity_component.ComponentWithLogging):
7180
act_component.set_logging_channel(
72-
self._component_logging.get_channel('__act__').append
81+
lambda datum: self._component_logging.publish_datum('__act__', datum)
7382
)
7483
if isinstance(context_processor, entity_component.ComponentWithLogging):
7584
context_processor.set_logging_channel(
76-
self._component_logging.get_channel('__context_processor__').append
85+
lambda datum: self._component_logging.publish_datum(
86+
'__context_processor__', datum
87+
)
7788
)
7889

90+
@property
91+
def measurements(self) -> measurements_lib.Measurements:
92+
return self._component_logging
93+
7994
def get_all_logs(self):
8095
return self._component_logging.get_all_channels()
8196

concordia/prefabs/entity/basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def build(
189189
agent_name=entity_name,
190190
act_component=act_component,
191191
context_components=components_of_agent,
192+
measurements=self.params.get('measurements'),
192193
)
193194

194195
return agent

concordia/prefabs/entity/basic_scripted.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def build(
158158
agent_name=entity_name,
159159
act_component=act_component,
160160
context_components=components_of_agent,
161+
measurements=self.params.get('measurements'),
161162
)
162163

163164
return agent

concordia/prefabs/entity/basic_with_plan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def build(
174174
agent_name=entity_name,
175175
act_component=act_component,
176176
context_components=components_of_agent,
177+
measurements=self.params.get('measurements'),
177178
)
178179

179180
return agent

concordia/prefabs/entity/conversational.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def build(
206206
agent_name=entity_name,
207207
act_component=act_component,
208208
context_components=components_of_agent,
209+
measurements=self.params.get('measurements'),
209210
)
210211

211212
return agent

concordia/prefabs/entity/fake_assistant_with_configurable_system_prompt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def build(
9090
agent_name=entity_name,
9191
act_component=act_component,
9292
context_components=components_of_agent,
93+
measurements=self.params.get('measurements'),
9394
)
9495

9596
return agent

concordia/prefabs/entity/minimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def build(
146146
agent_name=agent_name,
147147
act_component=act_component,
148148
context_components=components_of_agent,
149+
measurements=self.params.get('measurements'),
149150
)
150151

151152
return agent
152-

concordia/prefabs/entity/puppet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ def build(
8181
agent_name=name,
8282
act_component=act_comp,
8383
context_components=components,
84+
measurements=self.params.get("measurements"),
8485
)

concordia/prefabs/entity/rational.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,5 @@ def build(
185185
agent_name=entity_name,
186186
act_component=act_component,
187187
context_components=components_of_agent,
188+
measurements=self.params.get('measurements'),
188189
)

concordia/prefabs/game_master/async_social_media.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def build(
242242
agent_name=name,
243243
act_component=act_component,
244244
context_components=components_of_game_master,
245+
measurements=self.params.get('measurements'),
245246
)
246247

247248
return game_master

0 commit comments

Comments
 (0)