Package for managing agent memory in AI applications
Project description
AgentMemory Package
Description
AgentMemory is a Python package for managing agent memory structures in AI applications. It provides a flexible data model for long-term and short-term memory and supports storing and managing:
- Persona: Information and properties of an agent.
- Conversation: Conversations between agents and users.
- ConversationItems: Individual messages or actions within a conversation.
- Workflows: Workflows executed by agents.
- WorkflowSteps: Individual steps within a workflow.
Additionally, a cache system is provided for fast access and temporary storage.
Installation
Install the package using pip or uv:
pip install agentmemory-py
# or
uv add agentmemory-py
Quickstart
Create a Memory Object
from agentmemory import AgentMemory
from agentmemory.connection import AgentMemoryConnection
from agentmemory.connection.longterm import MongoDBConnection
from agentmemory.connection.shortterm import RedisConnection
con = AgentMemoryConnection(
longterm_con=MongoDBConnection(
mongo_uri="mongodb://localhost:27017",
database="support-agentmemory"
),
shortterm_con=RedisConnection(
host="localhost"
)
)
memory = AgentMemory("support-agentmemory", con=con)
Manage Conversations
Create a New Conversation
from agentmemory.schema.conversations import Conversation
conversation = Conversation(
title="New Conversation",
)
created_conversation = memory.conversations.create(conversation)
print(created_conversation)
List Conversations
# Get all conversations
conversations = memory.conversations.list()
# Get only 5 conversations
conversations = memory.conversations.list(limit=5)
# Filter by title
conversations = memory.conversations.list(query={"title": "title1"})
Retrieve and Update a Conversation
id = "<ID>"
conversation = memory.conversations.get(id)
conversation.title = "Updated Title"
memory.conversations.update(conversation)
Delete a Conversation
id = "<ID>"
memory.conversations.delete(id)
Manage ConversationItems
from agentmemory.schema.conversations import ConversationItem
item = ConversationItem(
conversation_id="<CONVERSATION_ID>",
role="system",
content="Hello, how can I help?",
data={
"custom": "data"
}
)
created_item = memory.conversation_items.create(item)
print(created_item)
# Get items of a conversation
items = memory.conversation_items.list_by_conversation_id("<CONVERSATION_ID>")
Manage Personas
from agentmemory.schema.personas import Persona
persona = Persona(
name="<NAME>",
role="<ROLE>",
goals="<GOALS>",
background="<BACKGROUND>",
data={
"custom": "data"
}
)
created_persona = memory.personas.create(persona)
print(created_persona)
# Retrieve persona by name
persona = memory.personas.get_by_name("<NAME>")
Manage Workflows and WorkflowSteps
from agentmemory.schema.workflows import Workflow, WorkflowStep, WorkflowStatus
workflow = Workflow(
conversation_item_id="<CONVERSATION_ITEM_ID>",
user_query="<USER_QUERY>",
status=WorkflowStatus.RUNNING,
data={
"custom": "data"
}
)
created_workflow = memory.workflows.create(workflow)
print(created_workflow)
step = WorkflowStep(
workflow_id=created_workflow.workflow_id,
name="<NAME>",
tool="<TOOL_NAME>",
arguments={
"arg1": "value1"
},
status=WorkflowStatus.SUCCESS,
result="<RESULT>",
logs=[],
data={
"custom": "data"
}
)
created_step = memory.workflow_steps.create(step)
print(created_step)
Custom Caching
The integrated cache system enables fast access to frequently used data.
memory.cache.keys("*") # List all keys
memory.cache.get("<KEY>") # Get value
memory.cache.set("<KEY>", {"key": "value"}) # Set value
memory.cache.clear("<PATTERN>") # Clear cache by pattern
Tests
To run the tests:
uv run pytest
License
MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentmemory_py-0.0.5.tar.gz.
File metadata
- Download URL: agentmemory_py-0.0.5.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b32c0ba43e32d9f96cc8b752148df408efece98137a0756f64abc2aa00544464
|
|
| MD5 |
2eb51db36ae6ef52fdd66250931fa0f1
|
|
| BLAKE2b-256 |
39a49faf71563fbfb61345d99913250511de107f83aefcd3d16ef13f24ff898e
|
Provenance
The following attestation bundles were made for agentmemory_py-0.0.5.tar.gz:
Publisher:
release.yml on enricogoerlitz/agentmemory-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentmemory_py-0.0.5.tar.gz -
Subject digest:
b32c0ba43e32d9f96cc8b752148df408efece98137a0756f64abc2aa00544464 - Sigstore transparency entry: 297799622
- Sigstore integration time:
-
Permalink:
enricogoerlitz/agentmemory-py@d910ff3ffc3052130292af1654a01157edee3ff5 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/enricogoerlitz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d910ff3ffc3052130292af1654a01157edee3ff5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agentmemory_py-0.0.5-py3-none-any.whl.
File metadata
- Download URL: agentmemory_py-0.0.5-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83f7edfdd64b7297c24c2c3916588264f0c111b04458f047e37275c5a38c20f4
|
|
| MD5 |
aa0c707119b2d93a9d159f45b0f37049
|
|
| BLAKE2b-256 |
646ef77019835a5177b449cba806f1f600a02d968b60c635b6551bab45757bc7
|
Provenance
The following attestation bundles were made for agentmemory_py-0.0.5-py3-none-any.whl:
Publisher:
release.yml on enricogoerlitz/agentmemory-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentmemory_py-0.0.5-py3-none-any.whl -
Subject digest:
83f7edfdd64b7297c24c2c3916588264f0c111b04458f047e37275c5a38c20f4 - Sigstore transparency entry: 297799664
- Sigstore integration time:
-
Permalink:
enricogoerlitz/agentmemory-py@d910ff3ffc3052130292af1654a01157edee3ff5 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/enricogoerlitz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d910ff3ffc3052130292af1654a01157edee3ff5 -
Trigger Event:
push
-
Statement type: