From b245d4d4df493ae9da39b1f8b5876fb203fe3df5 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 5 Mar 2024 06:24:08 -0800 Subject: [PATCH] more tests --- prompts/general/talk.txt | 4 ++++ src/agents.py | 4 +++- test.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/prompts/general/talk.txt b/prompts/general/talk.txt index c97c055..d557348 100644 --- a/prompts/general/talk.txt +++ b/prompts/general/talk.txt @@ -34,6 +34,10 @@ Before answering, consider "{{agent.meta_questions|random}}" Provide {{agent}}'s response from the first person point of view. +{% if topic %} +Maybe you could discuss the topic of "{{topic}}" +{% endif %} + keep responses to under 3 sentences. Craft an informal spoken response. diff --git a/src/agents.py b/src/agents.py index a96f2f0..620856c 100644 --- a/src/agents.py +++ b/src/agents.py @@ -288,7 +288,8 @@ def summarize_conversation(self, timestamp): print_and_log(interaction, f"{self.matrix.id}:events:{self.name}") self.addMemory("conversation", interaction, timestamp, random.randint(4, 6)) - 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}}) + 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 def talk(self, opts={}): @@ -363,6 +364,7 @@ def talk(self, opts={}): 'selfContext': self.getSelfContext(), 'relevant_memories': relevant_memories_string, 'agent': self, + 'topic': opts.get('topic',None), 'convo_types': all_convo_types[:10], 'connections': self.connections, 'meta_questions': self.meta_questions or "", diff --git a/test.py b/test.py index 87cc6dd..3b612ba 100644 --- a/test.py +++ b/test.py @@ -254,6 +254,44 @@ def test_embeddings(self): print(f"Current Memory: {mem}") print(f"Relevance Score: {Memory.calculateRelevanceScore(mem.embedding, context_embedding)}") self.assertTrue(len(sorted_memory) > 0) + + def test_information_spreading(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 test_talk_stranger(self): agent1_data = { "name": "Viktor",