display logs
This commit is contained in:
1 parent
dc9875bcd0
commit
a7cc529e38
2 files changed
+39
-17
No files matched your search
@@ -152,7 +152,7 @@ class CharacterAgent(Agent):
|
|||||||
memories = []
|
memories = []
|
||||||
|
|
||||||
if thread_context and thread_context['thread_id'] == message.thread_id:
|
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:
|
else:
|
||||||
thread_context = {'thread_id': message.thread_id}
|
thread_context = {'thread_id': message.thread_id}
|
||||||
|
|
||||||
@@ -179,24 +179,29 @@ class CharacterAgent(Agent):
|
|||||||
sender=self.id,
|
sender=self.id,
|
||||||
content=controller_response,
|
content=controller_response,
|
||||||
thread_id=current_thread.id,
|
thread_id=current_thread.id,
|
||||||
kind='debug',
|
kind='log',
|
||||||
|
subkind='debug',
|
||||||
)
|
)
|
||||||
|
|
||||||
sections = parse_sections(controller_response)
|
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']
|
if 'topic_focus' in sections:
|
||||||
thread_context['focus'] = topic_focus['focus']
|
topic_focus = parse_json_object(sections['topic_focus'])
|
||||||
self.app.save_agent_resource(self.id, 'last-thread-context', message.chat_id, thread_context)
|
|
||||||
|
|
||||||
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
|
# Encode a thread's messages as a string to pass to the agent
|
||||||
def serialize_thread_history(self, thread, ignore_message_ids=[]):
|
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)
|
is_self = is_digit and str(sender) == str(self.id)
|
||||||
return self.name if is_self else sender
|
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):
|
def get_memory_collection(self):
|
||||||
collection_name = f"agent_{self.id}_memory"
|
collection_name = f"agent_{self.id}_memory"
|
||||||
return collection_name
|
return collection_name
|
||||||
|
|
||||||
async def retrieve_topic_memories(self, topic):
|
async def retrieve_topic_memories(self, topic, focus=None):
|
||||||
client = self.app.qdrant_client
|
client = self.app.qdrant_client
|
||||||
collection = self.get_memory_collection()
|
collection = self.get_memory_collection()
|
||||||
|
|
||||||
@@ -227,9 +232,14 @@ class CharacterAgent(Agent):
|
|||||||
query_text=topic,
|
query_text=topic,
|
||||||
limit=20
|
limit=20
|
||||||
)
|
)
|
||||||
|
if focus:
|
||||||
|
# TODO: deduplicate
|
||||||
|
query_result += client.query(
|
||||||
|
collection,
|
||||||
|
query_text=topic,
|
||||||
|
limit=20
|
||||||
|
)
|
||||||
# TODO:
|
# TODO:
|
||||||
# query_result += query(focus)
|
|
||||||
# deduplicate results
|
|
||||||
# initial importance-based ranking
|
# initial importance-based ranking
|
||||||
memories = [it.document for it in query_result]
|
memories = [it.document for it in query_result]
|
||||||
|
|
||||||
|
|||||||
@@ -372,6 +372,8 @@
|
|||||||
return ['note'];
|
return ['note'];
|
||||||
} else if (msg.type == 'message') {
|
} else if (msg.type == 'message') {
|
||||||
return ['message', msg.sender == 'user' ? 'sent' : 'received'];
|
return ['message', msg.sender == 'user' ? 'sent' : 'received'];
|
||||||
|
} else if (msg.type == 'log') {
|
||||||
|
return ['message', 'log'];
|
||||||
} else {
|
} else {
|
||||||
return ['info'];
|
return ['info'];
|
||||||
}
|
}
|
||||||
@@ -402,6 +404,11 @@
|
|||||||
<div class="content">{{msg.content}}</div>
|
<div class="content">{{msg.content}}</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template v-if="msg.type == 'log'">
|
||||||
|
<div class="sender">Log ({{msg.sender}})</div>
|
||||||
|
<div class="content">{{msg.content}}</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template v-if="msg.type == 'thread-header'">
|
<template v-if="msg.type == 'thread-header'">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
Thread {{msg.threadId}} ({{msg.messageCount}} messages)
|
Thread {{msg.threadId}} ({{msg.messageCount}} messages)
|
||||||
@@ -497,6 +504,11 @@
|
|||||||
margin-top: -5px; /* half message padding */
|
margin-top: -5px; /* half message padding */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message.log .content {
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
.input-container {
|
.input-container {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
background-color: var(--color-background-soft);
|
background-color: var(--color-background-soft);
|
||||||
|
|||||||
Reference in new issue
Block a user