display logs

This commit is contained in:
Shivering Ocelot committed 2025-07-17 11:38:20 -05:00
1 parent dc9875bcd0
commit a7cc529e38
2 files changed
+39 -17

No files matched your search

+27 -17
View File
@@ -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]