Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Mar 18, 2024
1 parent 8116c2e commit 4cdc453
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 25 deletions.
6 changes: 3 additions & 3 deletions prompts/general/summarize_conversation.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Your name is {{agent}}
You are talking with {{other_agent}}
You just spoke with {{other_agent}}

{{conversation_string}}

Summarize the conversation above in {{agent}}'s point of view.
List all important outcomes of the conversation:
Summarize the conversation in the first person point of view as {{agent}}.
Write it as a thought {{agent}} says to theirselves.
15 changes: 6 additions & 9 deletions prompts/general/talk.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
roleplay as {{agent}}
{{selfContext}}
{{relevant_memories}}
roleplay as {{agent}} talking to {% if other_agent == "stranger" %} a stranger you know nothing about. {% else %} {{other_agent}} {% endif %}


{% if other_agent == "stranger" %}
This is your first time talking to this stranger.
{{selfContext}}
{{agent}}'s previous memories:
{{relevant_memories}}

{% else %}

{% if primer %}
{% if other_agent != "stranger" and primer %}
prime your thoughts but dont mention: "{{primer}}".
{% endif %}

{{selfContext}}
Below is the current chat history between {{agent}} and {{other_agent}}.

{{previous_conversations}}
Expand Down Expand Up @@ -41,5 +37,6 @@ Maybe you could discuss the topic of "{{topic}}"

keep responses to under 3 sentences.
Craft an informal spoken response.
Do not discuss topics for things that you don't perceive or are not in your recent memories.
Only write the response from {{agent}} and nothing else.

5 changes: 3 additions & 2 deletions src/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,11 @@ def summarize_conversation(self, timestamp):

msg = llm.prompt(prompt_name="summarize_conversation", variables=variables)
interaction = f"{timestamp} - {self} summarized their conversation with {self.last_conversation.other_agent.name}: {msg}"
interaction = f"my conversation with {self.last_conversation.other_agent.name}: {msg}"
if self.matrix is not None:
print_and_log(interaction, f"{self.matrix.id}:events:{self.name}")

self.addMemory("conversation", interaction, timestamp, random.randint(4, 6))
self.addMemory("summary", interaction, timestamp, random.randint(4, 6))
if self.matrix:
self.matrix.add_to_logs({"step_type":"agent_set", "attribute_name": "convo", "attribute_data": {"status": "complete", "from":self.mid, "to":self.last_conversation.other_agent.mid, "convo_id":self.last_conversation.mid}})
self.last_conversation = None
Expand Down Expand Up @@ -595,7 +596,7 @@ def addMemory(self, kind, content, timestamp=None, score=None,embedding=None):


if kind == "observation":
if (self.matrix is not None and self.matrix.allow_observance_flag == 1):
if (self.matrix and self.matrix.allow_observance_flag == 1) or (self.matrix is None):
memory = Memory(kind, content, timestamp, timestamp, score,embedding)
self.memory.append(memory)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def boot(self):

# Add Zombies
for i in range(self.num_zombies):
zombie = Agent({ "name": f"Zombie_{i}", "kind": "zombie", "actions": ["kill"],"matrix":self })
zombie = Agent({ "name": f"killer Zombie {i}", "kind": "zombie", "actions": ["kill"],"matrix":self })
self.add_agent_to_simulation(zombie)

@classmethod
Expand Down
70 changes: 61 additions & 9 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ def test_fine_move_action_invalid_direction(self):
self.assertEqual(agent.y, 0)

def test_fine_move_action_moves_away(self):
#real agent here, real zombie here. decide
matrix = Matrix({"environment":"configs/small.tmj"})
real_agent = Agent({ "name": "John", "actions": ["fine_move"],"x":5,"y":5,"matrix":matrix })
matrix.add_agent_to_simulation(real_agent)
zombie = Agent({ "name": f"Zombie", "kind": "zombie", "actions": ["kill"],"x":6,"y":5,"matrix":matrix })
matrix.add_agent_to_simulation(zombie)
matrix.llm_action(real_agent, matrix.unix_time)
self.assertEqual(real_agent.x, 4)
successful_outcomes = 0
for _ in range(4):
matrix = Matrix({"environment": "configs/small.tmj"})
real_agent = Agent({"name": "John", "actions": ["fine_move"], "x": 5, "y": 5, "matrix": matrix})
matrix.add_agent_to_simulation(real_agent)
zombie = Agent({"name": f"killer Zombie", "kind": "zombie", "actions": ["kill"], "x": 6, "y": 5, "matrix": matrix})
matrix.add_agent_to_simulation(zombie)
matrix.llm_action(real_agent, matrix.unix_time)
if real_agent.x == 4:
successful_outcomes += 1

self.assertTrue(successful_outcomes >= 2)

def test_matrix_runs_step(self):
matrix = Matrix({"environment":"configs/small.tmj"})
Expand Down Expand Up @@ -260,13 +264,56 @@ def test_embeddings(self):
print(f"Relevance Score: {Memory.calculateRelevanceScore(mem.embedding, context_embedding)}")
self.assertTrue(len(sorted_memory) > 0)

def test_information_spreading(self):

def test_information_dissemination(self):
a1_data = { "name": "Viktor", "goal": "wants to throw a party next week" }
a2_data = { "name": "John", "description": "loves art" }
a3_data = { "name": "Paul", "description": "loves eating" }
agent1 = Agent(a1_data)
agent2 = Agent(a2_data)
agent3 = Agent(a3_data)
unix_time = 1704067200
timestamp = datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
for i in range(2):
timestamp = datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
response = agent1.talk({ "target": agent2.name, "other_agents": [agent2], "timestamp": timestamp })
msg = f"{agent1} said to {agent2}: {response}"
print(msg)
response = agent2.talk({ "target": agent1.name, "other_agents": [agent1], "timestamp": timestamp })
msg = f"{agent2} said to {agent1}: {response}"
print(msg)
unix_time = unix_time + 10
agent2.summarize_conversation(timestamp)
print("*"*20)
for i in range(2):
timestamp = datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
response = agent2.talk({ "target": agent3.name, "other_agents": [agent3], "timestamp": timestamp })
msg = f"{agent2} said to {agent3}: {response}"
print(msg)
response = agent3.talk({ "target": agent2.name, "other_agents": [agent2], "timestamp": timestamp })
msg = f"{agent3} said to {agent2}: {response}"
print(msg)
unix_time = unix_time + 10
agent3.summarize_conversation(timestamp)
print(f"{agent2} memories")
for mem in agent2.memory:
print(mem)
print(f"{agent3} memories")
for mem in agent3.memory:
print(mem)

def long_range_test_information_dissemination(self):
a1_data = { "name": "Viktor", "goal": "wants to throw a party next week" }
a2_data = { "name": "John", "description": "loves art" }
a3_data = { "name": "Paul", "description": "loves eating" }
agent1 = Agent(a1_data)
agent2 = Agent(a2_data)
agent3 = Agent(a3_data)
agents = [agent1, agent2, agent3]
for i, agent in enumerate(agents):
for other_agent in agents[i + 1:]:
agent.connections.append(str(other_agent))
other_agent.connections.append(str(agent))
unix_time = 1704067200
timestamp = datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
for i in range(2):
Expand All @@ -279,6 +326,11 @@ def test_information_spreading(self):
print(msg)
unix_time = unix_time + 10
agent2.summarize_conversation(timestamp)
interactions = ["saw a dog" ,"took a nap","chatted with a stranger", "ate lunch", "saw a bird", "saw a friend","saw a stranger", "saw a zombie"]
for i in range(50):
timestamp = datetime.fromtimestamp(unix_time+i).strftime("%Y-%m-%d %H:%M:%S")
interaction = random.choice(interactions)
agent2.addMemory("observation", interaction, timestamp, random.randint(0, 2))
print("*"*20)
for i in range(2):
timestamp = datetime.fromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
Expand Down
3 changes: 2 additions & 1 deletion utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def generate(self, prompt, fallback="Llm Error"):
pd(f"current url {current_url}")
pd(f"INPUT:\n {prompt}")
pd(f"OUTPUT:\n {msg}")
pd(f"runtime: {end_time - start_time}")
print(f"LLM CALL: {prompt[:30]}")
print(f"runtime: {end_time - start_time}")

return msg

def embeddings(self, prompt, fallback=[0.5, 0.5, 0.5]):
Expand Down

0 comments on commit 4cdc453

Please sign in to comment.