Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e2c88d9
Assistant checkpoint: Set up web interface and fix API key configuration
VishwasK Dec 17, 2024
6b6a572
Assistant checkpoint: Update settings and add OpenAI API key configur…
VishwasK Dec 17, 2024
79bb325
Assistant checkpoint: Add error handling to chat endpoint and respons…
VishwasK Dec 17, 2024
e91175a
Assistant checkpoint: Update main.py with better error handling and d…
VishwasK Dec 17, 2024
228c99d
Assistant checkpoint
VishwasK Dec 17, 2024
8d0ec95
Assistant checkpoint: Improve error handling and response display
VishwasK Dec 17, 2024
face214
Assistant checkpoint: Created new software engineer agent profile
VishwasK Dec 17, 2024
a36099e
Assistant checkpoint: Update chat endpoint to handle agent responses …
VishwasK Dec 17, 2024
a0d00c7
Assistant checkpoint: Fix chat endpoint response handling
VishwasK Dec 17, 2024
ef67d3d
Assistant checkpoint: Update response handling in main.py
VishwasK Dec 17, 2024
5259665
Assistant checkpoint: Fix agent response handling in chat endpoint
VishwasK Dec 17, 2024
9a26909
Assistant checkpoint: Improve agent response handling and error manag…
VishwasK Dec 17, 2024
42c72cb
Assistant checkpoint: Fix agent response handling
VishwasK Dec 17, 2024
c74205b
Assistant checkpoint: Add token limits to GPT requests
VishwasK Dec 17, 2024
9fd6745
Assistant checkpoint: Add agent selector and improve chat interface
VishwasK Dec 17, 2024
00a3fb5
Assistant checkpoint: Add searchable agent dropdown and info display
VishwasK Dec 17, 2024
7571df0
Assistant checkpoint: Add PostgreSQL schema and database utilities
VishwasK Dec 17, 2024
af548bf
Assistant checkpoint: Improve agent search with better type handling …
VishwasK Dec 17, 2024
24f36fc
Assistant checkpoint: Add multiple search fields for agent attributes
VishwasK Dec 17, 2024
dec73d7
Assistant checkpoint: Add search functionality across both agent dire…
VishwasK Dec 17, 2024
9442d17
Assistant checkpoint: Install psycopg2 and fix chat endpoint
VishwasK Dec 17, 2024
b23f767
Assistant checkpoint: Fix search functionality and add database depen…
VishwasK Dec 17, 2024
ba1a975
Assistant checkpoint: Update search endpoint to work with files
VishwasK Dec 17, 2024
eda5c41
Assistant checkpoint: Update chat endpoint to fix agent initialization
VishwasK Dec 17, 2024
939536b
Assistant checkpoint: Enable message input after agent selection
VishwasK Dec 17, 2024
d1be71c
Assistant checkpoint: Clean up agent utterance response formatting
VishwasK Dec 17, 2024
810e2f1
Assistant checkpoint: Clean up response display to remove JSON structure
VishwasK Dec 17, 2024
47125df
modified to have webui for conversations
VishwasK Dec 17, 2024
a24d16c
Assistant checkpoint: Add agent management features with web UI
VishwasK Dec 17, 2024
85fba82
Assistant checkpoint: Update agent creation and management UI flow
VishwasK Dec 17, 2024
97e280e
Assistant checkpoint: Add missing uuid import to fix agent creation
VishwasK Dec 17, 2024
80867fc
Assistant checkpoint: Fix agent creation by initializing empty agent …
VishwasK Dec 17, 2024
d31c489
Assistant checkpoint: Fix reflection endpoint initialization and erro…
VishwasK Dec 17, 2024
41f4a1f
Assistant checkpoint: Fix reflection endpoint initialization and erro…
VishwasK Dec 17, 2024
178d931
Assistant checkpoint: Add missing MemoryStream import
VishwasK Dec 17, 2024
b8b28f3
Assistant checkpoint
VishwasK Dec 17, 2024
0b663af
Assistant checkpoint: Fix agent initialization for reflection endpoint
VishwasK Dec 17, 2024
942bdc8
Assistant checkpoint: Fix memory addition endpoint
VishwasK Dec 17, 2024
5013218
Assistant checkpoint: Fix reflection generation with proper parameters
VishwasK Dec 17, 2024
c0dddaf
Assistant checkpoint: Fix reflection generation in agent and endpoint
VishwasK Dec 17, 2024
0bfdd73
Assistant checkpoint: Update reflection handling in memory stream
VishwasK Dec 17, 2024
531f948
Assistant checkpoint: Add missing filterAgents function
VishwasK Dec 17, 2024
b7afed5
added UI components for creating and managing agent as well as search…
VishwasK Dec 17, 2024
246fb87
Update README.md
VishwasK Dec 22, 2024
c9a73ee
Create settings.py
VishwasK Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
modules = ["python-3.12"]
run = "python main.py"

[nix]
channel = "stable-24_05"

[deployment]
run = ["sh", "-c", "python main.py"]

[[ports]]
localPort = 3000
externalPort = 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Press CTRL+C to quit
172.31.196.3 - - [17/Dec/2024 14:39:55] "GET / HTTP/1.1" 200 -
[2024-12-17 14:40:09,391] ERROR in app: Exception on /chat [POST]
Traceback (most recent call last):
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/main.py", line 22, in chat
response = agent.utterance(history + [["User", message]])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/genagents.py", line 135, in utterance
ret = utterance(self, curr_dialogue, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/interaction.py", line 185, in utterance
return run_gpt_generate_utterance(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/interaction.py", line 170, in run_gpt_generate_utterance
output, prompt, prompt_input, fail_safe = chat_safe_generate(
^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/simulation_engine/gpt_structure.py", line 143, in chat_safe_generate
response = func_clean_up(response, prompt=prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/interaction.py", line 159, in _func_clean_up
utterance = extract_first_json_dict(gpt_response)["utterance"]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
172.31.196.3 - - [17/Dec/2024 14:40:09] "POST /chat HTTP/1.1" 500 -
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Traceback (most recent call last):
File "/home/runner/genagentsVishwas/main.py", line 35, in <module>
conversation.start()
File "/home/runner/genagentsVishwas/main.py", line 23, in start
agent_response = self.agent.utterance(self.conversation_history)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/genagents.py", line 135, in utterance
ret = utterance(self, curr_dialogue, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/interaction.py", line 184, in utterance
agent_desc = _utterance_agent_desc(agent, anchor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/interaction.py", line 36, in _utterance_agent_desc
retrieved = agent.memory_stream.retrieve([anchor], 0, n_count=120)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/memory_stream.py", line 387, in retrieve
x = extract_relevance(curr_nodes, self.embeddings, focal_pt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/genagents/modules/memory_stream.py", line 265, in extract_relevance
focal_embedding = get_text_embedding(focal_pt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/simulation_engine/gpt_structure.py", line 162, in get_text_embedding
response = openai.embeddings.create(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/openai/_utils/_proxy.py", line 25, in __getattr__
proxied = self.__get_proxied__()
^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/openai/_utils/_proxy.py", line 61, in __get_proxied__
return self.__load__()
^^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/openai/_module_client.py", line 54, in __load__
return _load_client().embeddings
^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/openai/__init__.py", line 305, in _load_client
_client = _ModuleClient(
^^^^^^^^^^^^^^
File "/home/runner/genagentsVishwas/.pythonlibs/lib/python3.12/site-packages/openai/_client.py", line 92, in __init__
raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ print(response["responses"])

Due to participant privacy concerns, the full agent bank containing over 1,000 generative agents based on real interviews is not publicly available at the moment. However, we plan to make aggregated responses on fixed tasks accessible for general research use in the coming months. Researchers interested in accessing individual responses on open tasks can request restricted access by contacting the authors and following a review process that ensures ethical considerations are met.

## Using Web UI

If you prefer to use web UI please take a look at latest changes which were made using Replit. You should be able to import the GIT repository in replit and deploy to see web UI.

## Contributing

We welcome contributions to enhance the functionality and usability of this project. If you are interested in contributing, please follow these steps:
Expand Down Expand Up @@ -262,4 +266,4 @@ In addition, we thank Douglas Guilbeault, Amir Goldberg, Diyi Yang, Jeff Hancock

For questions or inquiries, please contact the corresponding author:

- **Joon Sung Park**: [joonspk@stanford.edu](mailto:joonspk@stanford.edu)
- **Joon Sung Park**: [joonspk@stanford.edu](mailto:joonspk@stanford.edu)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"node_id": 0,
"node_type": "observation",
"content": "Is from wealthy family. Family owned multiple properties in India",
"importance": 75,
"created": 1,
"last_retrieved": 1,
"pointer_id": null
},
{
"node_id": 1,
"node_type": "reflection",
"content": "Growing up in a wealthy family, I was surrounded by a sense of privilege that set the tone for my childhood. With multiple properties in India, my early years were filled with the comfort and security that wealth can provide. However, I often wonder how this environment shaped my understanding of relationships and the world around me. While I had access to opportunities that many could only dream of, I sometimes felt isolated from the realities faced by others. My childhood was a blend of luxury and introspection, and I find myself reflecting on how these experiences influenced my values and aspirations.",
"importance": 75,
"created": 1,
"last_retrieved": 1,
"pointer_id": [
0
]
},
{
"node_id": 2,
"node_type": "reflection",
"content": "Growing up in a wealthy family provided me with numerous opportunities and resources that shaped my perspective on career choices. I often grapple with the privilege I had, which allowed me to explore various paths without the same pressures that many face. However, this privilege also made me acutely aware of the disparities in the world, pushing me to consider how I can leverage my advantages to make a meaningful impact. I aspire to build a career that not only fulfills my ambitions but also contributes positively to society, bridging the gap between my fortunate upbringing and the realities that others endure.",
"importance": 85,
"created": 1,
"last_retrieved": 1,
"pointer_id": [
1,
0
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "5b5423c8-2dd4-402b-aa34-53c33dc0cb12"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"first_name": "Rajan",
"last_name": "Shetty",
"age": 60,
"sex": "Male",
"race": "Asian",
"occupation": "Venture capitalist with 10 Billion net worth. Stanford Graduate. IIT Madras graduate. ",
"political_views": "Moderate"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

[
{
"node_id": 0,
"node_type": "observation",
"content": "I lead a team of 6 engineers working on cloud infrastructure and distributed systems. We focus on scalability and reliability of our core services.",
"importance": 85,
"created": 1,
"last_retrieved": 1,
"pointer_id": null
},
{
"node_id": 1,
"node_type": "observation",
"content": "Recently completed a major project migrating our monolithic architecture to microservices, which improved system performance by 40%.",
"importance": 85,
"created": 2,
"last_retrieved": 2,
"pointer_id": null
},
{
"node_id": 2,
"node_type": "observation",
"content": "I enjoy mentoring junior developers and conducting technical design reviews. Collaboration and knowledge sharing are important parts of our team culture.",
"importance": 75,
"created": 3,
"last_retrieved": 3,
"pointer_id": null
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

{
"id": "software-engineer-001"
}
15 changes: 15 additions & 0 deletions agent_bank/populations/single_agent/software_engineer/scratch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

{
"first_name": "Alex",
"last_name": "Chen",
"age": 32,
"occupation": "Senior Software Engineer",
"company": "Fortune 500 Tech Company",
"location": "San Francisco Bay Area",
"education": "MS Computer Science",
"years_of_experience": 8,
"expertise": ["Cloud Computing", "Distributed Systems", "Python", "Java", "System Design"],
"role": "Technical Lead",
"personality_traits": ["analytical", "detail-oriented", "collaborative"],
"interests": ["technology", "software architecture", "machine learning", "hiking", "photography"]
}
98 changes: 98 additions & 0 deletions db/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

import os
import json
import psycopg2
from psycopg2.extras import Json
from pathlib import Path

def get_db_connection():
return psycopg2.connect(os.environ['DATABASE_URL'])

def import_agents():
conn = get_db_connection()
cur = conn.cursor()

base_path = Path(__file__).parent.parent / 'agent_bank/populations/gss_agents'

for agent_dir in base_path.iterdir():
if agent_dir.is_dir():
meta_file = agent_dir / 'meta.json'
scratch_file = agent_dir / 'scratch.json'

if meta_file.exists() and scratch_file.exists():
with open(meta_file) as f:
meta = json.load(f)
with open(scratch_file) as f:
data = json.load(f)

cur.execute("""
INSERT INTO agents (id, first_name, last_name, age, sex,
ethnicity, race, political_views, education,
occupation, religion, city, state, data)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
ON CONFLICT (id) DO UPDATE SET
data = EXCLUDED.data
""", (
meta['id'],
data.get('first_name'),
data.get('last_name'),
data.get('age'),
data.get('sex'),
data.get('ethnicity'),
data.get('race'),
data.get('political_views'),
data.get('highest_degree_received'),
data.get('work_status'),
data.get('religion'),
data.get('city'),
data.get('state'),
Json(data)
))

conn.commit()
cur.close()
conn.close()

def search_agents(**criteria):
conn = get_db_connection()
cur = conn.cursor()

query = "SELECT id, first_name, last_name, age, sex, race, occupation, religion, data FROM agents WHERE 1=1"
params = []

if 'age' in criteria:
query += " AND age = %s"
params.append(int(criteria['age']))
if 'sex' in criteria:
query += " AND LOWER(sex) = LOWER(%s)"
params.append(str(criteria['sex']))
if 'race' in criteria:
query += " AND LOWER(race) = LOWER(%s)"
params.append(str(criteria['race']))
if 'religion' in criteria:
query += " AND LOWER(religion) = LOWER(%s)"
params.append(str(criteria['religion']))
if 'occupation' in criteria:
query += " AND LOWER(occupation) = LOWER(%s)"
params.append(str(criteria['occupation']))

cur.execute(query, params)
columns = [desc[0] for desc in cur.description]
results = [dict(zip(columns, row)) for row in cur.fetchall()]
cur.close()
conn.close()
return results

def search_agents_dialogue(age=None, sex=None, race=None, religion=None, occupation=None):
criteria = {}
if age:
criteria['age'] = age
if sex:
criteria['sex'] = sex
if race:
criteria['race'] = race
if religion:
criteria['religion'] = religion
if occupation:
criteria['occupation'] = occupation
return search_agents(**criteria)
26 changes: 26 additions & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

CREATE TABLE agents (
id UUID PRIMARY KEY,
first_name VARCHAR(100),
last_name VARCHAR(100),
age INTEGER,
sex VARCHAR(20),
ethnicity VARCHAR(100),
race VARCHAR(100),
political_views VARCHAR(100),
education VARCHAR(100),
occupation VARCHAR(100),
religion VARCHAR(100),
city VARCHAR(100),
state VARCHAR(2),
data JSONB -- Store full agent data
);

CREATE INDEX idx_agents_age ON agents(age);
CREATE INDEX idx_agents_sex ON agents(sex);
CREATE INDEX idx_agents_ethnicity ON agents(ethnicity);
CREATE INDEX idx_agents_race ON agents(race);
CREATE INDEX idx_agents_political_views ON agents(political_views);
CREATE INDEX idx_agents_education ON agents(education);
CREATE INDEX idx_agents_religion ON agents(religion);
CREATE INDEX idx_agents_location ON agents(city, state);
5 changes: 4 additions & 1 deletion genagents/genagents.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ def reflect(self, anchor, time_step=0):

Parameters:
anchor: str reflection anchor
time_step: int time step for the reflection
Returns:
None
"""
self.memory_stream.reflect(anchor, time_step)
if not hasattr(self, 'memory_stream'):
self.memory_stream = MemoryStream([], {})
self.memory_stream.reflect(anchor=anchor, reflection_count=1, time_step=time_step)


def categorical_resp(self, questions):
Expand Down
Loading