Skip to main content

No project description provided

Project description

agent_memory_jojo

# IntelligentMemoryManager Setup and Usage Guide

Introduction

The IntelligentMemoryManager is a memory management module designed to store and recall episodic memory for AI interactions. It leverages the Qdrant vector database to store and retrieve past conversations, enabling AI systems to recall user-specific context for more personalized and coherent responses.


How to Use


Getting Started

Prerequisites

Ensure you have the following installed on your system:

  • Python 3.10+
  • pip (Python package installer)

Installation

a. Clone the repository:

git clone https://github.com/danielAdama/agent_memory_jojo.git
cd agent_memory_jojo
  1. Create an Environment File: Create a .env file in the root directory of the project with the following command:
touch .env

After the creation of the .env, add the following environment variables:

OPENAI_API_KEY=<your-openai-api-key>
  1. Install dependencies:
poetry install
poetry shell

Importing the Module

To use the IntelligentMemoryManager, import it from the agent_memory_jojo.processors.intelligent module:

import dotenv
dotenv.load_dotenv(dotenv.find_dotenv(), override=True)
from agent_memory_jojo.processors.intelligent import IntelligentMemoryManager

b. Install from PIP:

pip install agent_memory_jojo

Initializing the Memory Manager

You need to initialize the IntelligentMemoryManager with a unique user_id:

processor = IntelligentMemoryManager(user_id="user12345")

Adding Memory

Memory should be structured as a conversation between the user and the AI assistant. Example:

memory = [
{'role': 'user',
  'content': "I've been manually trading for years but now shifting to algorithmic high-frequency scalping. Given market noise and rapid price moves, how should I design a solid risk management framework? I'm considering dynamic stop-loss algorithms, adaptive position sizing, and ML for signal detection. What indicators and data feeds should I prioritize for low-latency and optimal execution?"},
 {'role': 'assistant',
  'content': 'For high-frequency scalping, focus on tick data, VWAP, and order book imbalance to track micro price movements. Implement dynamic stop-losses that adjust to real-time volatility and use adaptive position sizing based on statistical models like the Kelly Criterion. Machine learning, particularly reinforcement learning, can refine entry/exit signals. Prioritize direct market data feeds for minimal latency and validate strategies with Monte Carlo simulations. Want to dive deeper into any of these areas?'}
]

To add this memory to the Qdrant vector database:

processor.add(memory)
2025-02-14 00:37:52,613 - processors.intelligent - INFO - Total existing memories: 0
2025-02-14 00:37:54,610 - processors.intelligent - INFO - {'id': '0', 'summary': 'The user is transitioning to algorithmic high-frequency scalping and seeks guidance on risk management frameworks, indicators, and data feeds for optimal execution.', 'event': 'ADD'}
2025-02-14 00:37:54,976 - client.qdrant_client - INFO - Collection 'episodic-memory' already exists----- Using episodic-memory collection.
100%|██████████| 1/1 [00:00<00:00, 13.59it/s]
2025-02-14 00:37:55,054 - client.qdrant_client - INFO - Embedding Completed
2025-02-14 00:37:55,054 - client.qdrant_client - INFO - Generating points
2025-02-14 00:37:55,376 - client.qdrant_client - INFO - Records inserted successfully.

To check the operation carried out for the added memory to the Qdrant vector database:

processor.get_relevant_operation()
{'result': [{'id': '3f81e9af-7715-45ec-af04-66a17f03e52b',
   'memory': {'summary': 'The user is transitioning to algorithmic high-frequency scalping and seeks guidance on risk management frameworks, indicators, and data feeds for optimal execution.'},
   'event': 'ADD'}]}

Example of Data Stored in Qdrant

{
  "metadata": {
    "id": "3f81e9af-7715-45ec-af04-66a17f03e52b",
    "user_id": "user12345",
    "summary": "The user is transitioning to algorithmic high-frequency scalping and seeks guidance on risk management frameworks, indicators, and data feeds for optimal execution.",
    "document_type": "preference",
    "memory_type": "long_term_memory"
  },
  "page_content": "The user is transitioning to algorithmic high-frequency scalping and seeks guidance on risk management frameworks, indicators, and data feeds for optimal execution."
}

Recalling Past Interactions

To search for past conversations related to a query, use the search function:

results = processor.search("I want to trade but i am worried transitioning?")
print(results)

Example Output

[{'id': '3f81e9af-7715-45ec-af04-66a17f03e52b',
  'summary': 'The user is transitioning to algorithmic high-frequency scalping and seeks guidance on risk management frameworks, indicators, and data feeds for optimal execution.'}]

Full Test

import dotenv
dotenv.load_dotenv(dotenv.find_dotenv(), override=True)
from agent_memory_jojo.processors.intelligent import IntelligentMemoryManager
from openai import chat

processor = IntelligentMemoryManager(user_id="user12345")

query="I want to trade but i am worried transitioning?"
# Get relevant past interactions
relevant_memories = processor.search(query)
# Build context from relevant history
memories_str = "Previous relevant summary:\n"+"\n".join(f"- {entry['summary']}" for entry in relevant_memories)

base_prompt = f"""
{memories_str}

Provide a helpful response that takes into account any relevant past interactions.
"""

system_prompt = f"""
{base_prompt}

You are a helpful trading assistant. keep your response short.
"""

messages=[
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": query}
]
response = chat.completions.create(
    model="gpt-4o-mini",
    stream=False,
    messages=messages
)
assistant_response = response.choices[0].message.content
messages.append({"role": "assistant", "content": assistant_response})

Conclusion

By using the IntelligentMemoryManager, AI systems can maintain long-term contextual memory, improving engagement and personalization. This guide outlines the setup, data storage, and retrieval processes for effectively managing AI-driven episodic memory.

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

agent_memory_jojo-0.1.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

agent_memory_jojo-0.1.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file agent_memory_jojo-0.1.1.tar.gz.

File metadata

  • Download URL: agent_memory_jojo-0.1.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.9 Darwin/23.5.0

File hashes

Hashes for agent_memory_jojo-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9ccbb1675c3e20b20b628562b39ea97262c3b677ad3b59ede833513282ceff18
MD5 b536f209130b4c518b8513b13e6204eb
BLAKE2b-256 ad8b070efd15f19330aa5cc2466de54b52b2f1bc1a7e65621a68a9f2dd8e89ef

See more details on using hashes here.

File details

Details for the file agent_memory_jojo-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: agent_memory_jojo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.9 Darwin/23.5.0

File hashes

Hashes for agent_memory_jojo-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa7e111c9940d706860efc82042e5b5cc7730be6e30ae555b0fd489fce826c3b
MD5 dbe27903d378df6757fb416ebe652a74
BLAKE2b-256 6a8c39681a0551517ee50541cda68320282233aa8bc91acd2ff909980ae319d3

See more details on using hashes here.

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