diff --git a/backend/src/agents/character.py b/backend/src/agents/character.py index 6f9e417..8f73181 100644 --- a/backend/src/agents/character.py +++ b/backend/src/agents/character.py @@ -152,7 +152,7 @@ class CharacterAgent(Agent): memories = [] if thread_context and thread_context['thread_id'] == message.thread_id: - memories = retrieve_topic_memories(thread_context['topic']) + memories = await self.retrieve_topic_memories(thread_context['topic']) else: thread_context = {'thread_id': message.thread_id} @@ -179,24 +179,29 @@ class CharacterAgent(Agent): sender=self.id, content=controller_response, thread_id=current_thread.id, - kind='debug', + kind='log', + subkind='debug', ) sections = parse_sections(controller_response) - self.app.send_chat_message( - chat_id=message.chat_id, - sender=self.id, - content=sections['response'], - thread_id=current_thread.id, - ) - topic_focus = parse_json_object(sections['topic_focus']) + if 'response' in sections: + self.app.send_chat_message( + chat_id=message.chat_id, + sender=self.id, + content=sections['response'], + thread_id=current_thread.id, + ) - thread_context['topic'] = topic_focus['topic'] - thread_context['focus'] = topic_focus['focus'] - self.app.save_agent_resource(self.id, 'last-thread-context', message.chat_id, thread_context) + if 'topic_focus' in sections: + topic_focus = parse_json_object(sections['topic_focus']) - new_memories = parse_json_array(sections['new_memories']) + thread_context['topic'] = topic_focus['topic'] + thread_context['focus'] = topic_focus['focus'] + self.app.save_agent_resource(self.id, 'last-thread-context', message.chat_id, thread_context) + + if 'new_memories' in sections: + new_memories = parse_json_array(sections['new_memories']) # Encode a thread's messages as a string to pass to the agent def serialize_thread_history(self, thread, ignore_message_ids=[]): @@ -209,13 +214,13 @@ class CharacterAgent(Agent): is_self = is_digit and str(sender) == str(self.id) return self.name if is_self else sender - return "\n".join(f"[{sender_name(message)}]: {message.content}" for message in messages) + return "\n".join(f"{sender_name(message)}: {message.content}" for message in messages if message.kind == 'message') def get_memory_collection(self): collection_name = f"agent_{self.id}_memory" return collection_name - async def retrieve_topic_memories(self, topic): + async def retrieve_topic_memories(self, topic, focus=None): client = self.app.qdrant_client collection = self.get_memory_collection() @@ -227,9 +232,14 @@ class CharacterAgent(Agent): query_text=topic, limit=20 ) + if focus: + # TODO: deduplicate + query_result += client.query( + collection, + query_text=topic, + limit=20 + ) # TODO: - # query_result += query(focus) - # deduplicate results # initial importance-based ranking memories = [it.document for it in query_result] diff --git a/frontend/src/views/Chat.vue b/frontend/src/views/Chat.vue index d6fd74b..aa6e617 100644 --- a/frontend/src/views/Chat.vue +++ b/frontend/src/views/Chat.vue @@ -372,6 +372,8 @@ return ['note']; } else if (msg.type == 'message') { return ['message', msg.sender == 'user' ? 'sent' : 'received']; + } else if (msg.type == 'log') { + return ['message', 'log']; } else { return ['info']; } @@ -402,6 +404,11 @@
{{msg.content}}
+ +