Skip to content

Commit

Permalink
feat: add in-context message field ('in_context') to message dicts re…
Browse files Browse the repository at this point in the history
…turned by `GET /api/agents/{a_id}/messages` (#1135)
  • Loading branch information
cpacker authored Mar 12, 2024
1 parent 8fa9026 commit 225564d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions memgpt/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@ def get_agent_messages(self, user_id: uuid.UUID, agent_id: uuid.UUID, start: int
# Slice the list for pagination
messages = reversed_messages[start:end_index]

# Convert to json
# Add a tag indicating in-context or not
json_messages = [{**record.to_json(), "in_context": True} for record in messages]

else:
# need to access persistence manager for additional messages
db_iterator = memgpt_agent.persistence_manager.recall_memory.storage.get_all_paginated(page_size=count, offset=start)
Expand All @@ -826,8 +830,13 @@ def get_agent_messages(self, user_id: uuid.UUID, agent_id: uuid.UUID, start: int
# return messages in reverse chronological order
messages = sorted(page, key=lambda x: x.created_at, reverse=True)

# convert to json
json_messages = [record.to_json() for record in messages]
# Convert to json
# Add a tag indicating in-context or not
json_messages = [record.to_json() for record in messages]
in_context_message_ids = [str(m.id) for m in memgpt_agent._messages]
for d in json_messages:
d["in_context"] = True if str(d["id"]) in in_context_message_ids else False

return json_messages

def get_agent_archival(self, user_id: uuid.UUID, agent_id: uuid.UUID, start: int, count: int) -> list:
Expand Down

0 comments on commit 225564d

Please sign in to comment.