Skip to content

v0.3.19

Compare
Choose a tag to compare
@sarahwooders sarahwooders released this 14 Jul 23:48
· 331 commits to main since this release
5a30f7e

Support for custom memory classes

MemGPT now supports customizeable memory classes by extending the BaseMemory class. This allows developers to both define custom memory fields (instead of just human/persona) as well as custom memory editing functions (rather than core_memory_[append/replace]. Note that custom memory editing functions will need to have properly formatted docstrings so that the function can be added as a custom tool to the agent.

Default ChatMemory class

Agents will default to using the ChatMemory class, which has the original human/memory fields and memory editing functions in MemGPT:

from memgpt.memory import BaseMemory

class ChatMemory(BaseMemory):

    def __init__(self, persona: str, human: str, limit: int = 2000):
        self.memory = {
            "persona": MemoryModule(name="persona", value=persona, limit=limit),
            "human": MemoryModule(name="human", value=human, limit=limit),
        }

    def core_memory_append(self, name: str, content: str) -> Optional[str]:
        """
        Append to the contents of core memory.

        Args:
            name (str): Section of the memory to be edited (persona or human).
            content (str): Content to write to the memory. All unicode (including emojis) are supported.

        Returns:
            Optional[str]: None is always returned as this function does not produce a response.
        """
        self.memory[name].value += "\n" + content
        return None

    def core_memory_replace(self, name: str, old_content: str, new_content: str) -> Optional[str]:
        """
        Replace the contents of core memory. To delete memories, use an empty string for new_content.

        Args:
            name (str): Section of the memory to be edited (persona or human).
            old_content (str): String to replace. Must be an exact match.
            new_content (str): Content to write to the memory. All unicode (including emojis) are supported.

        Returns:
            Optional[str]: None is always returned as this function does not produce a response.
        """
        self.memory[name].value = self.memory[name].value.replace(old_content, new_content)
        return None

Improve agent creation interface

Custom tools and memory classes can now both be specified in the agent creation API:

from memgpt.memory import ChatMemory

# create agent with default tools/memory 
basic_agent = client.create_agent()

# create agent with custom tools and memory
tool = client.create_tool(...)
memory = CustomMemory(human="I am Sarah", persona="I am Sam", organization="MemGPT")
custom_agent = client.create_agent(
    name="my_agent", memory=memory, tools=[tool.name]
)

The memory editing bools from the extended BaseMemory class are automatically added as tools to the agent to use.

Deprecation of Presets

Since specification of tools, memory, and the system prompt is now moving into the agent creation interface, we are no longer supporting presets as a mechanism to create agents.

Migration Script

We provide a migration script for migrating agents from v0.3.18 to this version (due to changes in the AgentState schema).

What's Changed

New Contributors

Full Changelog: 0.3.18...0.3.19