From 8148dab8a89e6edd304b95de1584afa3eef3a5ac Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Fri, 13 Jun 2025 16:24:59 -0700 Subject: [PATCH] feat: tune file tools prompting (#2652) --- letta/constants.py | 3 --- letta/functions/function_sets/files.py | 8 ++++---- letta/services/agent_manager.py | 7 ------- letta/services/tool_executor/files_tool_executor.py | 5 ++--- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/letta/constants.py b/letta/constants.py index 412c5e19..aab388bf 100644 --- a/letta/constants.py +++ b/letta/constants.py @@ -292,9 +292,6 @@ 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." -) # Throw an error message when a read-only block is edited READ_ONLY_BLOCK_EDIT_ERROR = f"{ERROR_MESSAGE_PREFIX} This block is read-only and cannot be edited." diff --git a/letta/functions/function_sets/files.py b/letta/functions/function_sets/files.py index cf7bd229..f3a2ea72 100644 --- a/letta/functions/function_sets/files.py +++ b/letta/functions/function_sets/files.py @@ -7,10 +7,10 @@ if TYPE_CHECKING: async def open_file(agent_state: "AgentState", file_name: str, view_range: Optional[Tuple[int, int]]) -> str: """ - Open up a file in core memory. + Open the file with name `file_name` and load the contents into files section in core memory. Args: - file_name (str): Name of the file to view. + file_name (str): Name of the file to view. Required. view_range (Optional[Tuple[int, int]]): Optional tuple indicating range to view. Returns: @@ -21,7 +21,7 @@ async def open_file(agent_state: "AgentState", file_name: str, view_range: Optio async def close_file(agent_state: "AgentState", file_name: str) -> str: """ - Close a file in core memory. + Close file with name `file_name` in files section in core memory. Args: file_name (str): Name of the file to close. @@ -48,7 +48,7 @@ async def grep(agent_state: "AgentState", pattern: str, include: Optional[str] = async def search_files(agent_state: "AgentState", query: str) -> List["FileMetadata"]: """ - Get list of most relevant files across all data sources. + Get list of most relevant files across all data sources using embedding search. Args: query (str): The search query. diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py index dc292d1f..c7f8628d 100644 --- a/letta/services/agent_manager.py +++ b/letta/services/agent_manager.py @@ -15,7 +15,6 @@ from letta.constants import ( BASE_TOOLS, BASE_VOICE_SLEEPTIME_CHAT_TOOLS, BASE_VOICE_SLEEPTIME_TOOLS, - DATA_SOURCE_ATTACH_ALERT, FILES_TOOLS, MULTI_AGENT_TOOLS, ) @@ -1717,13 +1716,7 @@ class AgentManager: await agent.update_async(session, actor=actor) # Force rebuild of system prompt so that the agent is updated with passage count - # and recent passages and add system message alert to agent pydantic_agent = await self.rebuild_system_prompt_async(agent_id=agent_id, actor=actor, force=True) - await self.append_system_message_async( - agent_id=agent_id, - content=DATA_SOURCE_ATTACH_ALERT, - actor=actor, - ) return pydantic_agent diff --git a/letta/services/tool_executor/files_tool_executor.py b/letta/services/tool_executor/files_tool_executor.py index 53979312..df0b60cf 100644 --- a/letta/services/tool_executor/files_tool_executor.py +++ b/letta/services/tool_executor/files_tool_executor.py @@ -126,15 +126,14 @@ class LettaFileToolExecutor(ToolExecutor): await self.files_agents_manager.update_file_agent_by_id( agent_id=agent_state.id, file_id=file_id, actor=self.actor, is_open=True, visible_content=visible_content ) - - return "Success" + return f"Successfully opened file {file_name}, lines {start} to {end} are now visible in memory block <{file_name}>" async def close_file(self, agent_state: AgentState, file_name: str) -> str: """Stub for close_file tool.""" await self.files_agents_manager.update_file_agent_by_name( agent_id=agent_state.id, file_name=file_name, actor=self.actor, is_open=False ) - return "Success" + return f"Successfully closed file {file_name}, use function calls to re-open file" def _validate_regex_pattern(self, pattern: str) -> None: """Validate regex pattern to prevent catastrophic backtracking."""