v0.3.19
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
- chore: bump version to 0.3.18 by @sarahwooders in #1483
- fix: fix main.yml test by @sarahwooders in #1484
- feat: move tool functions to user by @sarahwooders in #1487
- feat: migration script for 0.3.17 by @sarahwooders in #1489
- feat: refactor
CoreMemory
to support generalized memory fields and memory editing functions by @sarahwooders in #1479 - fix: use timestamp passed by request for user message created date by @goetzrobin in #1503
- fix: patch type error by @cpacker in #1506
- fix: dos2unix text files by @cpacker in #1507
- chore:
.gitattributes
by @cpacker in #1511 - fix: bug fixing for #1455 - not able to serialize json for Azure by @ljhskyso in #1495
- chore: update dev portal by @cpacker in #1514
- fix: remove duplicate
send_message
functions by @sarahwooders in #1519 - fix: use params in get_all_users(GET) endpoint by @yuleisheng in #1518
- fix: update docs to say 'stream_steps = True' by @yuleisheng in #1531
- fix: Fixed issue #1523 by @Vinayak21574 in #1526
- fix: fix example scripts by @sarahwooders in #1536
- fix: add memory tools from dev portal by @sarahwooders in #1540
- feat: migration script for version 0.3.18 by @sarahwooders in #1541
- chore: bump version 0.3.19 by @sarahwooders in #1542
New Contributors
- @ljhskyso made their first contribution in #1495
- @yuleisheng made their first contribution in #1518
- @Vinayak21574 made their first contribution in #1526
Full Changelog: 0.3.18...0.3.19