@@ -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
0 commit comments