Skip to content

Commit 4c300ad

Browse files
authored
Merge pull request #30 from GilesStrong/feat/memory_maintenance
Feat/memory maintenance
2 parents 627d660 + 39807e5 commit 4c300ad

38 files changed

Lines changed: 2763 additions & 107 deletions

README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ An older version of this project may be found here https://github.com/GilesStron
2222

2323
- High-level backend/frontend architecture and flows: [`docs/developer-architecture-guide.md`](docs/developer-architecture-guide.md)
2424
- Dedicated deck-building flow guide: [`docs/deck-building.md`](docs/deck-building.md)
25+
- AI memory system architecture, maintenance, and operations: [`docs/memory-system.md`](docs/memory-system.md)
2526

2627
## Fresh Clone Setup (Docker)
2728

@@ -131,26 +132,27 @@ If you run Ollama in a separate compose project, attach it to `llm_net` using a
131132

132133
```yaml
133134
services:
134-
ollama:
135-
image: ollama/ollama:latest
136-
container_name: ollama
137-
restart: unless-stopped
138-
volumes:
139-
- ~/infra/ollama:/root/.ollama
140-
networks:
141-
- llm_net
142-
- 127.0.0.1:11434:11434
143-
deploy:
144-
resources:
145-
reservations:
146-
devices:
147-
- driver: nvidia
148-
count: all
149-
capabilities: [gpu]
135+
ollama:
136+
image: ollama/ollama:latest
137+
container_name: ollama
138+
restart: unless-stopped
139+
volumes:
140+
- ~/infra/ollama:/root/.ollama
141+
ports:
142+
- "127.0.0.1:11434:11434"
143+
networks:
144+
- llm_net
145+
deploy:
146+
resources:
147+
reservations:
148+
devices:
149+
- driver: nvidia
150+
count: all
151+
capabilities: [gpu]
150152

151153
networks:
152-
llm_net:
153-
name: llm_net
154+
llm_net:
155+
name: llm_net
154156
```
155157
156158
After starting Ollama, pull the models referenced by your `.env` (`EMBEDDING_MODEL`), for example:
@@ -210,6 +212,25 @@ Run frontend tests:
210212
docker compose exec frontend bun run test --run
211213
```
212214

215+
## Memory System Operations
216+
217+
The AI memory system is integrated into deck generation and automatically maintained by Celery beat.
218+
219+
- Full guide: [`docs/memory-system.md`](docs/memory-system.md)
220+
- Scheduled maintenance task: `appai.tasks.memory_maintenance.run_memory_maintenance_task`
221+
222+
Run maintenance manually (direct graph execution):
223+
224+
```bash
225+
docker compose exec web python app/manage.py shell -c "import asyncio; from appai.services.graphs.memory_maintenance import run_memory_maintenance; asyncio.run(run_memory_maintenance())"
226+
```
227+
228+
Queue maintenance via Celery (requires `celery_llm_worker` running):
229+
230+
```bash
231+
docker compose exec web python app/manage.py shell -c "from appai.tasks.memory_maintenance import run_memory_maintenance_task; run_memory_maintenance_task.delay()"
232+
```
233+
213234
## Production Server Commands
214235

215236
```bash
@@ -318,7 +339,7 @@ docker compose \
318339
--project-name deepmtg_2_prod \
319340
--env-file .env.prod \
320341
-f docker-compose.prod.yml \
321-
run --rm web python manage.py migrate
342+
run --rm web python app/manage.py migrate
322343
323344
docker compose \
324345
--project-name deepmtg_2_prod \

app/app/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@
225225
"task": "appai.tasks.daily_theme.make_daily_theme",
226226
"schedule": crontab(minute="*/30"), # every 30 minutes, but only completes once a day due to early exit
227227
},
228+
"daily-memory-maintenance-job": {
229+
"task": "appai.tasks.memory_maintenance.run_memory_maintenance_task",
230+
"schedule": crontab(minute="*/30"), # every 30 minutes, but only completes once a day due to early exit
231+
},
228232
"cleanup-old-deck-build-tasks": {
229233
"task": "appai.tasks.cleanup.cleanup_old_deck_build_tasks",
230234
"schedule": crontab(minute="*/30"), # every 30 minutes

app/appai/dataclasses/__init__.py

Whitespace-only changes.

app/appai/dataclasses/memory.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2026 Giles Strong
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from uuid import UUID
15+
16+
from pydantic import BaseModel, Field
17+
18+
19+
class Memory(BaseModel):
20+
name: str = Field(
21+
max_length=64, description="The name of the memory, which can be used to reference it in future queries."
22+
)
23+
text: str = Field(description="The content of the memory, which can be any text that the agent wants to remember.")
24+
related_card_uuids: set[UUID] = Field(
25+
default_factory=set,
26+
max_length=10,
27+
description="A list of UUIDs of cards that are related to this memory, which can be used to link the memory to specific cards and retrieve it later based on those cards. Up to 10 related card UUIDs can be included.",
28+
)
29+
30+
31+
class ExistingMemory(Memory):
32+
id: UUID = Field(
33+
description="The unique identifier of the memory in the database, used for referencing and updating the memory."
34+
)
35+
created_at: str = Field(
36+
description="The timestamp of when the memory was created in the database, used for tracking the age of the memory and determining if it may be obsolete or in need of consolidation with newer memories."
37+
)

0 commit comments

Comments
 (0)