Skip to main content

Package for managing agent memory in AI applications

Project description

AgentMemory Package

CI release

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>",
    content="Hello, how can I help?"
)

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="SupportAgent",
    description="Helps users with support requests."
)

created_persona = memory.personas.create(persona)
print(created_persona)

# Retrieve persona by name
persona = memory.personas.get_by_name("SupportAgent")

Manage Workflows and WorkflowSteps

from agentmemory.schema.workflows import Workflow, WorkflowStep

workflow = Workflow(
    name="Support Workflow",
    description="Handles support tickets."
)

created_workflow = memory.workflows.create(workflow)
print(created_workflow)

step = WorkflowStep(
    workflow_id=created_workflow.id,
    name="Check Ticket"
)

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>", "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

agentmemory_py-0.0.4.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentmemory_py-0.0.4-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file agentmemory_py-0.0.4.tar.gz.

File metadata

  • Download URL: agentmemory_py-0.0.4.tar.gz
  • Upload date:
  • Size: 41.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agentmemory_py-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7707c213c970274fb04ee644a5a1a50b0a0ce4e8eb6c1fcb25d82d78a963f506
MD5 24502d181492e887d0c41cc1a947f186
BLAKE2b-256 e1497f936edee2fc99e77af6007266fbc84a2dab44b3108ee14f44bd83266573

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentmemory_py-0.0.4.tar.gz:

Publisher: release.yml on enricogoerlitz/agentmemory-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentmemory_py-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: agentmemory_py-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agentmemory_py-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 37ebef87bbb6fdcf25e2a014516cc4cb766ac5ba104bbe3873472d6cac8c8b0f
MD5 a1ced9a8f87ac77e3b88495317719f31
BLAKE2b-256 3e9603d892b0f49e9cb783d534936aa2b1df59e9d791a7940286b402062e1c9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentmemory_py-0.0.4-py3-none-any.whl:

Publisher: release.yml on enricogoerlitz/agentmemory-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page