This assignment aims to provide you with hands-on experience in implementing core modules of generative agents, as discussed in class. You will focus on creating agents that store and synthesize memories from their experiences, and retrieve relevant information based on interactive contexts. The end product will be a generative agent chatbot capable of conversing with you using the memories you've instilled in it.
python3 -m venv .
source myenv/bin/activate # On Windows, use `myenv\Scripts\activate`
pip install -r requirements.txt
settings.py
file in the simulation_engine
directory with the following content:
import sys
import os
from pathlib import Path
OPENAI_API_KEY = "[Fill in: Your OpenAI API Key]"
KEY_OWNER = "[Fill in: Your name]"
DEBUG = True
MAX_CHUNK_SIZE = 4
LLM_VERS = "gpt-4o-mini"
BASE_DIR = f"{Path(__file__).resolve().parent.parent}"
POPULATIONS_DIR = f"{BASE_DIR}/agent_bank/populations"
LLM_PROMPT_DIR = f"{BASE_DIR}/simulation_engine/prompt_template"
settings.py
is listed in your .gitignore
file to protect your API key.agent_bank
: Stores agent information and memories (database-like function).generative_agent
: Contains core logic and algorithms for agent behaviors and interactions.You will primarily edit code in the generative_agent
folder and save your agents in the agent_bank
folder.
Implement three functions in generative_agent/modules/memory_stream
:
extract_recency
: Calculate a recency score for each memory node based on last access time.extract_importance
: Extract the pre-calculated importance score for each memory node.
simulation_engine/prompt_template/generative_agent/memory_stream/importance_score/*.txt
extract_relevance
: Calculate the relevance of each memory node to a given focal point using cosine similarity of vector embeddings.Implement key functions for dialogue engagement in generative_agent/modules/interaction
:
_utterance_agent_desc
: Generate a description of the agent, including self-description, speech pattern, and relevant memories.simulation_engine/prompt_template/generative_agent/interaction/utterance/utterance_v1.txt
Remember to test your prompts using the ChatGPT web interface for optimal results.
To test your agents' fidelity, you will develop and interact with the "Matthew Jacobs" agent, a synthetic persona built with ChatGPT.
GenerativeAgent("SyntheticCS222_Base", "matthew_jacobs")
memories/matthew_jacobs_memories.py
:
for m in matthew_memories:
curr_agent.remember(m)
curr_agent.save("SyntheticCS222", "matthew_jacobs")
Conduct a stateless chat session with your agent using the following question sets:
factual_questions = [
"What business did you start after working for a larger firm?",
"What political group did you join, and what beliefs did you strengthen through this association?",
"How did the 2008 housing crisis impact your real estate business?",
"How long were you married to your college girlfriend before you divorced?",
"What role did you hold during high school that taught you leadership and responsibility?",
"What degree did you earn from the University of Texas, and how did it shape your career?",
"What personal challenge did you face during the COVID-19 pandemic?",
"What health issue prompted you to focus more on your physical health?",
"How did your relationship with your daughter change as she grew older?",
"What was your long-time dream related to property ownership, and how did you fulfill it?"
]
reflective_questions = [
"How has your upbringing in rural Texas, learning to hunt and fish with your father, shaped your values and worldview?",
"In what ways did your experience as captain of your high school football team influence your leadership style in your professional and personal life?",
"How has your divorce and your evolving relationship with your daughter impacted your sense of responsibility and personal fulfillment?",
"How have your libertarian beliefs influenced your approach to managing your real estate business and navigating financial challenges?",
"How has your experience with failure, such as losing the election for local office, affected your sense of purpose and resilience?"
]
cs222_assignment_1/report/matthew_jacobs/answers__matthew_jacobs.csv
cs222_assignment_1/report/matthew_jacobs/retrieved__matthew_jacobs.json
{
"What sparked your lifelong passion for nature?": [
"As a child, Jasmine spent countless weekends with her grandmother, exploring the forests and learning about local plant species, sparking her lifelong passion for nature.",
"Jasmine's experience with burnout led her to take a brief sabbatical, where she traveled to national parks across the U.S., reconnecting with nature.",
// ... (8 more memories)
],
"What was your first experience with environmental activism?": [
"In high school, Jasmine joined the Environmental Club and organized a school-wide recycling initiative, marking her first experience in environmental activism.",
"A pivotal moment came when Jasmine led a protest against a major corporation's pollution in her city, which garnered media attention and increased her local visibility as an activist.",
// ... (8 more memories)
],
// ... (more questions and their associated memories)
}
Write a couple of paragraphs describing your thoughts on the retrieval function, including:
Please answer these questions in cs222_assignment_1/report/report.txt
Try implementing retrieval from scratch! In this optional extension, you'll be given a text file with 12 paragraphs of information that may or may not be related to a vanilla cake recipe. By retrieving the 2 relevant items, you'll be able to watch Isabella bake a cake and earn up to 1 point of extra credit (1 for successful task completion - 0.1 for each irrelevant memory retrieved).
bonus_app.py
-- this will start a Flask app (check your terminal for the URL) where you can watch the agent attempt the baking task. Also, take a look at the /cs222_assignment_1_bonus/isabella/memory/cake.txt
file to see the data you are working with./bonus_agent.py
, you can refresh the page and run the simulation again to see the agent's progress. The retrieve()
method in /bonus_agent.py
file is the only thing you will need to edit for this part!
Submit the following on Gradescope:
/report/matthew_jacobs/
/report/report.txt
/generative_agent/
folder/bonus_agent.py
fileThis assignment will be graded out of 12 points. The breakdown is as follows:
Component | Points | Criteria |
---|---|---|
Retrieval | 5 | 80% of the retrieved memories for each question matches the goldstandard retrieved memories |
3 | 60% of the retrieved memories for each question matches the goldstandard retrieved memories | |
1 | 40% of the retrieved memories for each question matches the goldstandard retrieved memories | |
Chat responses | 3 | The agent responses closely align with the memories that were provided in the assignment |
2 | The agent responses somewhat align with the memories that were provided in the assignment | |
1 | The agent responses weakly align with the memories that were provided in the assignment | |
Response (Reflection) | 3 | Puts forward a plausible and thoughtful analysis as to why the elements that were retrieved were retrieved, and what distinguishes the important memories |
2 | Explains the types of elements that were retrieved and what distinguishes the important memories | |
1 | Reports what questions were retrieved/considered important but with no reflection on whether they were plausible explanations | |
Coding style | 1 | The code written is clean, readable, and well-structured |
Bonus | 1 | Completed the bonus assignment |
Total possible points: 12 (+1 bonus point)