A library for managing LLM conversations and context
Project description
Generic LLM Memorizer
Library for managing AI agent memory through automatic fact extraction, knowledge graph building, and SKOS ontology storage.
Features
- Fact Extraction: Automatically extracts relevant facts from conversations (preferences, skills, context, events)
- User Profile: Builds and maintains a user profile (name, age, hobbies, occupation)
- Conversation Summary: Generates concise summaries of conversations
- Knowledge Graph: Builds an RDF-style knowledge graph as triplets (Subject → Predicate → Object)
- SKOS Knowledge Base: Stores ontological concepts following the SKOS standard
- Search: Semantic search through facts and SKOS concepts
- Persistence: All data stored in JSON format
Installation
uv sync
Usage
Basic Setup
import asyncio
from generic_llm_memorizer.llm_memorizer import LLMMemorizer
from pydantic import BaseModel
# Define your LLM call function
async def llm_call(prompt: str, system_prompt: str, response_model: type[BaseModel]):
# Implement your LLM call here (OpenAI, Anthropic, Ollama, etc.)
# Return an instance of response_model
pass
# Initialize memorizer with a list of conversation messages (strings)
memorizer = LLMMemorizer(
user_id="user_123",
session_id="session_1",
llm_call=llm_call,
conversation=[
"User: Bonjour, je m'appelle Marie et je suis développeuse Python",
"Assistant: Enchantée Marie ! Bienvenue."
]
)
# Consolidate memory (extract facts, summary, knowledge graph, SKOS)
memory, summary = await memorizer.consolidate()
print(f"Summary: {summary}")
print(f"Extracted {len(memory.facts)} facts")
Fact Structure
Each fact contains:
content: The fact textkind: Category (preference, context, skill, event, opinion, demographic)timestamp: Extraction dateduration_validity: Validity period (P1Y, P3M, P7D, etc.)
Knowledge Graph
Concepts stored as RDF triplets:
{
"concepts": [
{
"subject": {"name": "Marie", "type": "person"},
"predicate": {"name": "has profession", "type": "relation"},
"object": {"name": "developer", "type": "occupation"}
}
]
}
SKOS Knowledge Base
Ontological concepts following SKOS standard:
{
"scheme": {"prefLabel": "User Knowledge Database - user_123"},
"concepts": [
{
"prefLabel": "python-developer",
"definition": "A developer specialized in Python",
"broader": ["developer"],
"related": ["programming", "software-engineering"]
}
]
}
Searching
# Search facts
relevant_facts = await memorizer.search_facts("What does the user like?")
# Search SKOS concepts
relevant_concepts = await memorizer.search_skos("development skills")
Storage
Data persisted to ./memories/{user_id}/:
memory.json- User profile and factsknowledge_graph.json- RDF tripletsskos_knowledge_db.json- SKOS ontology{session_id}/conversation.json- Conversation history
Architecture
LLMMemorizer
├── memory/ → User profile + facts (memory.json)
├── knowledge_graph → RDF triplets (knowledge_graph.json)
├── skos_knowledge_db → SKOS concepts (skos_knowledge_db.json)
└── conversation → Message history
Dependencies
- Python 3.12+
- pydantic (data models)
- pytest (testing)
Project details
Release history Release notifications | RSS feed
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 generic_llm_memorizer-0.1.5.tar.gz.
File metadata
- Download URL: generic_llm_memorizer-0.1.5.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee67e3748b0a2fd9749d3bb238db0d840c7d6ab55a9167674d5e600a92f3a210
|
|
| MD5 |
347a5026720d2d81a92530b48d8bb30a
|
|
| BLAKE2b-256 |
a6095159434986b37bb8d91c80a8a577543469ff95b4bb22cf75ed6410e90e73
|
File details
Details for the file generic_llm_memorizer-0.1.5-py3-none-any.whl.
File metadata
- Download URL: generic_llm_memorizer-0.1.5-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
898295f2e7eacbdf46be3e0433f6c5d40204c8b6a4a79b2424a04431ee36d347
|
|
| MD5 |
04f3b759370d1905e357908f90f180de
|
|
| BLAKE2b-256 |
37d67b0cda87c74379d8c549e2c15aa4776484276b353eae6a8f1736813c3ee8
|