google-deepmind / concordia

A library for generative social simulation
Apache License 2.0
671 stars 161 forks source link

[BUG] Phase/EntityComponents functions is always needed in Minimal Agent? / agent_components_tutorial.ipynb #85

Closed SoyGema closed 1 month ago

SoyGema commented 1 month ago

Hello. First and foremost, thanks for releasing concordia! Under the context of reproducing agent_components_tutorial.ipynb the following backtrace is found when executing the minimal agent

Captura de pantalla 2024-09-25 a las 12 39 55
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-12-a883f7679477>](https://localhost:8080/#) in <cell line: 1>()
----> 1 agent.act()

7 frames
[/usr/lib/python3.10/concurrent/futures/thread.py](https://localhost:8080/#) in __init__(self, max_workers, thread_name_prefix, initializer, initargs)
    142             max_workers = min(32, (os.cpu_count() or 1) + 4)
    143         if max_workers <= 0:
--> 144             raise ValueError("max_workers must be greater than 0")
    145 
    146         if initializer is not None and not callable(initializer):

ValueError: max_workers must be greater than 0

After reviewing the codebase, added a minimal context / Phase / two EntityComponents empty functions according to the tutorial to the AppleEating ActingComponent , avoiding the ValueError from the ThreadPoolExecutor and after executing it shows ' Eat the apple' , which seems consistent.

class AppleEating(entity_component.ActingComponent):
    def get_action_attempt(self, context, action_spec) -> str:
        return "Eat the apple."

# Define a minimal context component
class ContextComponent(entity_component.ContextComponent):
    def pre_act(self, action_spec):
        return {}

    def post_act(self, action_spec):
        return {}

agent = entity_agent.EntityAgent(
    'Alice',
    act_component=AppleEating(),
    context_components={'my_context': ContextComponent()}
)

agent.act()

is this hypothesis fix correct ? (even empty EntityComponents functions declaration are always needed). Let me know if you would accept possible contribs ( update the notebook ). Please don´t feel forced to this . Please let me know if I misunderstood anything in order to learn more, just trying to understand the overall logic by testing everything. 🙏

vezhnick commented 1 month ago

Thank you for finding the bug! The problem was in the concorrency module, which would crash if the set of components is empty. We are fixing this now, after the fix the agent with no components should work fine.