feat: add view in editor tool for sleeptime agent (#1589)

This commit is contained in:
cthomas
2025-04-07 17:22:37 -07:00
committed by GitHub
parent 38d35aad52
commit 148727a44a
8 changed files with 85 additions and 30 deletions

View File

@@ -195,20 +195,36 @@ def finish_rethinking_memory(agent_state: "AgentState") -> None: # type: ignore
return None
def core_memory_insert(agent_state: "AgentState", target_block_label: str, line_number: int, new_memory: str) -> None: # type: ignore
def view_core_memory_with_line_numbers(agent_state: "AgentState", target_block_label: str) -> None: # type: ignore
"""
Insert new memory content into a core memory block at a specific line number.
View the contents of core memory in editor mode with line numbers. Called before `core_memory_insert` to see line numbers of memory block.
Args:
target_block_label (str): The name of the block to view.
Returns:
None: None is always returned as this function does not produce a response.
"""
return None
def core_memory_insert(agent_state: "AgentState", target_block_label: str, new_memory: str, line_number: Optional[int] = None, replace: bool = False) -> None: # type: ignore
"""
Insert new memory content into a core memory block at a specific line number. Call `view_core_memory_with_line_numbers` to see line numbers of the memory block before using this tool.
Args:
target_block_label (str): The name of the block to write to.
line_number (int): Line number to insert content into (0 for beginning of file).
new_memory (str): The new memory content to insert.
line_number (Optional[int]): Line number to insert content into, 0 indexed (None for end of file).
replace (bool): Whether to overwrite the content at the specified line number.
Returns:
None: None is always returned as this function does not produce a response.
"""
current_value = str(agent_state.memory.get_block(target_block_label).value)
current_value_list = current_value.split("\n")
if line_number is None:
line_number = len(current_value_list)
current_value_list.insert(line_number, new_memory)
new_value = "\n".join(current_value_list)
agent_state.memory.update_block_value(label=target_block_label, value=new_value)