Skip to content

feat(personalization): Personalization pipeline with Mem0 memory integration and terminal chat mode#540

Merged
aiosfoundation merged 15 commits into
agiresearch:mainfrom
RyamL1221:feature/personalization
Apr 15, 2026
Merged

feat(personalization): Personalization pipeline with Mem0 memory integration and terminal chat mode#540
aiosfoundation merged 15 commits into
agiresearch:mainfrom
RyamL1221:feature/personalization

Conversation

@RyamL1221
Copy link
Copy Markdown
Contributor

feat: Personalization pipeline with Mem0 memory integration and terminal chat mode

Summary

This PR adds a personalization pipeline to AIOS that enables context-aware LLM responses based on prior interactions. It includes memory storage/retrieval via Mem0, ChromaDB persistence infrastructure, dynamic Ollama model discovery, and a new terminal chat mode with intelligent intent routing.

Changes

1. Personalization Pipeline (aios/memory/, aios/syscall/)

  • ContextInjector (aios/memory/context_injector.py): Retrieves relevant memories from Mem0 before each chat LLM call and prepends them as a system message. Filters by relevance score and respects a configurable token budget.
  • ConversationExtractor (aios/memory/conversation_extractor.py): After each chat LLM call, stores the user+assistant exchange as a memory via a background daemon thread. Never blocks the LLM response.
  • Integration (aios/syscall/syscall.py): Wired into SyscallExecutor.execute_request() for action_type="chat" queries. ContextInjector runs before the LLM call, ConversationExtractor runs after. Personalization is only active in chat mode — file operations (action_type="operate_file") bypass the pipeline entirely.
  • Kernel wiring (runtime/launch.py): Personalization components initialized during initialize_components() when memory.provider is "mem0".

2. Mem0 Provider Enhancements (aios/memory/providers/mem0.py)

  • ChromaDB persistence: Injects a chromadb.PersistentClient to bypass Mem0 v1.0.11's deprecated chromadb.Client(Settings(...)) which is always in-memory in ChromaDB 1.5.5. Resolves paths to absolute, creates the persistence directory automatically.
  • Default path: When no path is configured for ChromaDB, defaults to .mem0/chroma relative to the project root.
  • Known limitation: Cross-restart memory recall doesn't work with small local Ollama models (e.g., qwen2.5:7b) because Mem0's fact extraction produces empty results. In-session personalization works correctly. The data suggests that larger models with stronger instruction-following (e.g., GPT-4, Claude) may produce better fact extraction results, but this has not been tested.

3. Terminal Chat Mode (aios/terminal/, scripts/run_terminal.py, runtime/run_terminal.py)

  • IntentRouter (aios/terminal/intent_router.py): Two-stage intent classifier — keyword heuristic (zero latency) with LLM fallback for ambiguous inputs. Classifies user input as chat or file operation.
  • Three modes: /auto (default, intelligent routing), /chat (all input → llm_chat() with personalization), /file (all input → llm_operate_file()).
  • Conversation history: Chat mode maintains session history so the LLM has context from prior messages.
  • Mode indicator: Prompt shows [auto], [chat], or [file] to indicate current mode.
  • Both scripts/run_terminal.py and runtime/run_terminal.py updated with identical routing behavior.

4. Kernel Stability (runtime/launch.py)

  • Fixed double-initialization bug: changed uvicorn.run("runtime.launch:app") to uvicorn.run(app) and added _ensure_initialized() guard. Components now initialize exactly once.

5. Configuration & CI

  • aios/config/config.yaml.example: Added qwen3:4b model, path option for ChromaDB, personalization settings documentation.
  • requirements.txt: Added hypothesis for property-based testing.
  • .github/workflows/test-ollama.yml: CI pulls both qwen3:1.7b and qwen3:4b.
  • .github/workflows/test-qdrant.yml: Minor CI updates.
  • .gitignore: Added .mem0/ directory.

New Files

File Purpose
aios/memory/context_injector.py Memory retrieval and injection before LLM calls
aios/memory/conversation_extractor.py Async conversation storage after LLM calls
aios/terminal/__init__.py Terminal package exports
aios/terminal/intent_router.py Keyword + LLM intent classification
tests/modules/llm/ollama/test_dynamic_registration_pbt.py 7 property-based tests for dynamic Ollama registration
tests/modules/memory/__init__.py Test package init

Testing

  • 7 property-based tests (Hypothesis) for Ollama dynamic registration — all pass
  • 4/4 concurrent Ollama CI tests pass (previously 2 failed)
  • 4/4 single Ollama CI tests pass
  • In-session personalization verified: name recall, preference tracking, conversation context
  • Terminal chat/file/auto mode switching verified with live kernel

Known Limitations

  • Cross-restart memory persistence requires models with strong instruction-following for Mem0's fact extraction step. Small local models (qwen2.5:7b) produce empty extraction results. The persistence infrastructure is in place and the data suggests larger models may resolve this, but cross-restart recall has not been verified with cloud-hosted models.
  • Conversation history in chat mode grows unbounded within a session. Future improvement: sliding window or token budget.
  • Redis connection errors in logs (Error 61 connecting to localhost:6379) are pre-existing — the LSFS file watcher tries to connect to Redis which isn't running locally.

@aiosfoundation aiosfoundation merged commit 2155966 into agiresearch:main Apr 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants