google-deepmind / concordia

A library for generative social simulation
Apache License 2.0
633 stars 148 forks source link

access entity components via keys that are a name field rather than class name #93

Closed mptouzel closed 2 weeks ago

mptouzel commented 2 weeks ago

Great work on this library! This is minor, but...

I have run into a use case where it really makes sense to have a single entity component class, but many instances.

As I understand, currently, the components are accessed via a dictionary whose keys are the names of the component class: https://github.com/google-deepmind/concordia/blob/01e4ad40e4721f35b884f1235f2b79b041a725e6/concordia/factory/agent/basic_agent.py#L196C3-L197C61

This restricts their use to only one instance, and so the only way to have many instances is to duplicate the same class, which is not really a good solution.

FIX: The obvious fix would be to add a name field to all component class definitions and use that as the key, rather than the class name.

jzleibo commented 2 weeks ago

Using the class name as the key is just a convention at the level of the agent factory. None of the code outside the factory file makes the assumption that the keys will be the class names. So you can name them however you like.

mptouzel commented 2 weeks ago

Ok! Good to know. Thanks.