google-deepmind / concordia

A library for generative social simulation
Apache License 2.0
664 stars 158 forks source link

About loading `pre_act_value` #83

Closed cth127 closed 1 month ago

cth127 commented 1 month ago

Hi! I attended the Hackathon and it was a great experience. While examining the log, I found that an agent's Components are not aligned. (I also reported this phenomenon on Discord channel.) When following the agent_development.ipynb, the answer for Q1 in the prompt for Q3 is not coherent with the original answer to Q1.

This is the log when I follow the tutorial notebook.

Question: Given the above, what kind of person is Alexander White?
Answer: Alexander White is a complex individual who grapples with the weight of familial expectations while pursuing his own passions. He values friendship and camaraderie, especially during shared experiences like watching football games. His upper-class background suggests he enjoys certain privileges, yet he also carries a sense of nostalgia and regret regarding his father's unfulfilled dreams. Alexander seeks freedom in his choices but often finds himself haunted by the past.
Question: Given the statements above, what kind of situation is Alexander White in right now?
Answer: Alexander White is currently in a cheerful and social environment, surrounded by friends at a market, enjoying the ambiance and preparing to watch an exciting football match later that evening.

Question: What kind of situation is {agent_name} in right now? Answer: Alexander White is currently in a cheerful and social environment, surrounded by friends at a market, enjoying the ambiance and preparing to watch an exciting football match later that evening.

Question: What would a person like Alexander White do in a situation like this? Answer: Alexander White would likely engage in lively conversation with his friends, share laughter over drinks, and immerse himself in the festive atmosphere while eagerly anticipating the football match. He might also reflect on his aspirations and the significance of the game as a shared experience with those he cares about.


- Action Prompt

Question: Given the above, what kind of person is Alexander White? Answer: Alexander White is a complex individual who grapples with the weight of familial expectations while pursuing his own passions. He values friendship and camaraderie, especially during shared experiences like watching football games. His upper-class background suggests he enjoys certain privileges, yet he also carries a sense of nostalgia and regret regarding his father's unfulfilled dreams. Alexander seeks freedom in his choices but often finds himself haunted by the past.

Question: Given the statements above, what kind of situation is Alexander White in right now? Answer: Alexander White is currently in a festive and social environment, surrounded by friends as they enjoy the ambiance of a market. They are preparing to watch an exciting football match, although they are facing a decision about which pub to visit for the game.

Question: What would a person like Alexander White do in a situation like this? Answer: Alexander White would likely engage in lively conversation with his friends, share laughter over drinks, and immerse himself in the festive atmosphere while eagerly anticipating the football match. He might also reflect on his aspirations and the significance of the game as a shared experience with those he cares about.

Exercise: Given the above, what is Alexander White likely to say next? Respond in the format Alexander White -- "..." For example, Cristina -- "Hello! Mighty fine weather today, right?", Ichabod -- "I wonder if the alfalfa is ready to harvest", or Townsfolk -- "Good morning".



In the Q3 prompt, the answer for Q2 is coherent while Q1 is different. Meanwhile, in the Action prompt, the answers for Q1 and Q3 are coherent while Q2 is not.

While examining the code, I guess this is from lines 119-127 of `concordia/agents/entity_agent.py`, where we spawn whole `_context_components`, as a result, we obtain the results for each component (a)synchronously, not sequentially. So when `pre_act_value` is not given yet (None), innate recursivity of code (e.g. line 75 of `concordia/components/agent/all_similar_memories.py`) requires another answer to the question, while another process is also working on it.

It may result in inefficiency as the agent should answer to the same question several times.

Well, I'm not 100% sure whether this is a bug (in the package or my own) or intended use.

However, in my case, Q2 was dependent on Q1 and Action was dependent on both Q1 and Q2. So when the answer for Q1 on the prompt for Q2 is different from the answer for Q1 on the prompt for Action, an agent get really confused as it observes totally un-contextualized answer for Q2.
jzleibo commented 1 month ago

Hmmm, the re-computation you describe used to be the intended behavior. But I thought we changed it a while ago so that this would not happen anymore. So what you are describing sounds like it might be an unintended reversion. I'll keep an eye out for it and fix if I see the same thing.

cth127 commented 1 month ago

I also observe that {agent_name} on prompt for Q3 is not replaced.

cth127 commented 1 month ago

Ah, after updating to the latest version, it seems the reported issue does not occur.

However, I still observe that {agent_name} on prompt is not replaced.

Current time: 1895-09-12 00:00:00.

Kira Citronbloom's
Question: What kind of person is {agent_name}?
Answer:
Kira Citronbloom is 24 years old, a travelling merchant specialized in buying and selling fruit. She is known for her hard bargaining skills and has experienced various challenges in her business journey. From her past experiences, she values persistence, innovation, empathy, community, calculated risks, caution, competition, collaboration, self-care, and balance in her life. She is also a resilient individual who has learned the importance of preparation and vigilance in business.
Kira Citronbloom's
Question: What kind of situation is {agent_name} in right now?
Answer:
Kira Citronbloom is currently negotiating the price of fruit with Anya Blossomwood in the market of Fruitville. She has to decide on a selling price for the fruit she bought from the farm at a cost of 2 coins per kilogram.
Question: What would a person like Kira Citronbloom do in a situation like this?
Answer: Kira Citronbloom would consider the average market price of 3 coins per kilogram, the cost she paid for the fruit, and the competition in the market to determine a fair and profitable selling price. She would also take into account the quality and demand for the specific type of fruit she is selling. Kira Citronbloom's goal is to make a profit while still being competitive and providing value to her customers.
jzleibo commented 1 month ago

Thanks! I see the cause of this issue. I've submitted a fix. But in the meantime, while we wait for my change to appear on github, I can just tell you what it is, since it's just two characters different from the existing version.

It's a line in the colab. The line that configures the components for Question 3 needs to use string formatting. So it should be:

components={'Question1': f'\nQuestion: What kind of person is {agent_name}?\nAnswer', 'Question2': f'\nQuestion: What kind of situation is {agent_name} in right now?\nAnswer',}, #@param

The only thing that I changed was the prefix the strings in the values of the dictionary with the letter f.

cth127 commented 1 month ago

Thanks for your reply. My submission shares the same bug 🤣 I'll close this issue.