serena.tools.memory_tools#


class WriteMemoryTool(agent)[source]#

Bases: Tool, ToolMarkerCanEdit

Write some information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format. The memory name should be meaningful.

Parameters:

agent (SerenaAgent)

apply(memory_name, content, max_chars=-1)[source]#

Write information about this project that can be useful for future tasks in md format. The name should be meaningful and can include “/” to organize into topics. If explicitly instructed, use the “global/” prefix for writing a memory that is shared across projects. References to other memories should be inside backticks and prefixed with mem:, e.g., mem:auth.

Parameters:
  • memory_name (str) – memory name

  • content (str) – memory content, utf8-encoded

  • max_chars (int) – see other tools

Return type:

str

class ReadMemoryTool(agent)[source]#

Bases: Tool

Reads the content of a memory file.

Parameters:

agent (SerenaAgent)

apply(memory_name)[source]#

Use to read a memory that is likely to be relevant to the current task, inferring relevance e.g. from the name.

Parameters:

memory_name (str)

Return type:

str

class ListMemoriesTool(agent)[source]#

Bases: Tool

Lists available memories.

Parameters:

agent (SerenaAgent)

apply(topic='')[source]#

Lists available memories, optionally filtered by topic.

Parameters:

topic (str)

Return type:

str

class DeleteMemoryTool(agent)[source]#

Bases: Tool, ToolMarkerCanEdit

Delete a memory file.

Parameters:

agent (SerenaAgent)

apply(memory_name)[source]#

Delete a memory, only call if instructed explicitly or permission was granted by the user.

Parameters:

memory_name (str)

Return type:

str

class RenameMemoryTool(agent)[source]#

Bases: Tool, ToolMarkerCanEdit

Renames or moves a memory, updating references that are marked with the mem: prefix.

Parameters:

agent (SerenaAgent)

apply(old_name, new_name)[source]#

Rename or move a memory, use “/” in the name to organize into topics. The “global” topic should only be used if explicitly instructed. References to other memories that are marked with the mem: prefix will be updated accordingly. References in read-only memories are not affected.

Parameters:
  • old_name (str)

  • new_name (str)

Return type:

str

class EditMemoryTool(agent)[source]#

Bases: Tool, ToolMarkerCanEdit

Replaces content matching a regular expression in a memory.

Parameters:

agent (SerenaAgent)

apply(memory_name, needle, repl, mode, allow_multiple_occurrences=False)[source]#

Replace content matching a regular expression in a memory.

Parameters:
  • memory_name (str) – the name of the memory

  • needle (str) – the string or regex pattern to search for. In regex mode, be careful to not replace too much! If mode is “literal”, this string will be matched exactly. If mode is “regex”, this string will be treated as a regular expression (syntax of Python’s re module, with the MULTILINE and DOTALL flags enabled).

  • repl (str) – the replacement string (verbatim).

  • mode (Literal['literal', 'regex']) – either “literal” or “regex”, specifying how the needle parameter is to be interpreted.

  • allow_multiple_occurrences (bool) – whether to allow matching and replacing multiple occurrences. If false and multiple occurrences are found, an error will be returned.

Return type:

str