feat: insert system message when source is attached (#1158)

This commit is contained in:
Sarah Wooders
2025-03-04 14:26:06 -08:00
committed by GitHub
parent 05b701e0bc
commit a7f9ed5405
2 changed files with 26 additions and 2 deletions

View File

@@ -146,6 +146,9 @@ MESSAGE_SUMMARY_WARNING_STR = " ".join(
# "Remember to pass request_heartbeat = true if you would like to send a message immediately after.",
]
)
DATA_SOURCE_ATTACH_ALERT = (
"[ALERT] New data was just uploaded to archival memory. You can view this data by calling the archival_memory_search tool."
)
# The ackknowledgement message used in the summarize sequence
MESSAGE_SUMMARY_REQUEST_ACK = "Understood, I will respond with a summary of the message (and only the summary, nothing else) once I receive the conversation history. I'm ready."

View File

@@ -4,7 +4,7 @@ from typing import Dict, List, Optional
import numpy as np
from sqlalchemy import Select, and_, func, literal, or_, select, union_all
from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLS, MAX_EMBEDDING_DIM, MULTI_AGENT_TOOLS
from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLS, DATA_SOURCE_ATTACH_ALERT, MAX_EMBEDDING_DIM, MULTI_AGENT_TOOLS
from letta.embeddings import embedding_model
from letta.helpers.datetime_helpers import get_utc_time
from letta.log import get_logger
@@ -670,6 +670,7 @@ class AgentManager:
ValueError: If either agent or source doesn't exist
IntegrityError: If the source is already attached to the agent
"""
with self.session_maker() as session:
# Verify both agent and source exist and user has permission to access them
agent = AgentModel.read(db_session=session, identifier=agent_id, actor=actor)
@@ -687,7 +688,27 @@ class AgentManager:
# Commit the changes
agent.update(session, actor=actor)
return agent.to_pydantic()
# Add system messsage alert to agent
self.append_system_message(
agent_id=agent_id,
content=DATA_SOURCE_ATTACH_ALERT,
actor=actor,
)
return agent.to_pydantic()
@enforce_types
def append_system_message(self, agent_id: str, content: str, actor: PydanticUser):
# get the agent
agent = self.get_agent_by_id(agent_id=agent_id, actor=actor)
message = PydanticMessage.dict_to_message(
agent_id=agent.id, user_id=actor.id, model=agent.llm_config.model, openai_message_dict={"role": "system", "content": content}
)
# update agent in-context message IDs
self.append_to_in_context_messages(messages=[message], agent_id=agent_id, actor=actor)
@enforce_types
def list_attached_sources(self, agent_id: str, actor: PydanticUser) -> List[PydanticSource]: