Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add in-context message field ('in_context') to message dicts returned by GET /api/agents/{a_id}/messages #1135

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
cpacker marked this conversation as resolved.
Show resolved Hide resolved
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
Loading