How memcore-agent/memcore works
Purpose and Entry Points
ailive_MemCore is a Python library for adding persistent, entity-oriented memory to an LLM agent. It combines a chat/ReAct agent, knowledge-graph retrieval, automatic memory updates, and persona/chat-history context.
• Library API: src/ailive/agent/chat_agent.py
• Memory package: src/ailive/MemCore/__init__.py
• Demo application entry point: MemCore_app/MemCore_app.py
Chat-Agent Orchestration
ChatAgent is the primary integration boundary for consumers. It accepts paths for system persona, user persona, chat history, MemCore stream, and entity knowledge store; it also exposes custom-tool registration/removal. The agent coordinates query handling, tool execution, retrieval, response generation, and persistence.
• src/ailive/agent/chat_agent.py
• src/ailive/agent/base_agent.py
• src/ailive/agent/data_types.py
Memory Model: Stream to Knowledge Store
The memory subsystem has two persistence representations. The MemCore stream records entity occurrences with timestamps (interaction breadth). The entity knowledge store aggregates stream entries into per-entity count and most-recent-reference metadata (depth/relevance). These are designed to feed subsequent response context and preference inference.
• src/ailive/MemCore/memcore_stream.py
• src/ailive/MemCore/entity_knowledge_store.py
• src/ailive/MemCore/types.py
Context Construction and Conversation State
Agent context is assembled from personas, retained/summarized chat history, relevant graph entities, and memory-derived entity rankings. File-backed JSON/text data enables the demo’s stateful operation; this is a persistence boundary rather than a transactional database interface.
• MemCore_app/data/MemCore_stream.json
• MemCore_app/data/entity_knowledge_store.json
• MemCore_app/data/past_chat.json
Knowledge Retrieval and Writeback
The intended retrieval design uses LlamaIndex-style graph querying: identify query entities, retrieve a bounded related subgraph, then use it as answer context. Agent responses are written back so future queries can retrieve newly learned entities. Development artifacts include serialized graph/vector/doc stores, suggesting local/offline index experimentation alongside the Neo4j-backed design described by the project.
• dev/recursive_retrieval/langchain_retrieval/retrieve.py
• dev/recursive_retrieval/entity_extraction/entity_extraction.py
• dev/KG_mecore_stream/storage_graph/ch1_2_3_4/docstore.json
Tools and Model Boundary
The agent supports a configurable default tool set (search, vision, location, stocks) plus arbitrary Python callables. LLM/tool adapters are separated from agent orchestration. Supported model runtimes are local Ollama models by default, with OpenAI model alternatives; external search and domain tools may require hosted API credentials.
• src/ailive/agent/llm_api/tools.py
• src/ailive/agent/llm_api
• src/ailive/synonym_expand/synonym.py
Infrastructure and External Services
Core infrastructure is Python (README limits runtime to Python ≤3.11.9), package dependencies from requirements.txt, and optional local Ollama. The documented production graph backend is Neo4j. Optional integrations require OpenAI, Perplexity, Google Maps, and Alpha Vantage credentials. The repository’s README references older streamlit_app paths; the checked-in UI is instead under MemCore_app/.
• requirements.txt
• MemCore.toml
• MemCore_app/MemCore_app.py
Main entry points: chat_agent.py ChatAgent · __init__.py MemCore package · memcore_stream.py MemCore stream · entity_knowledge_store.py Entity knowledge store
Components 15
Agent runtime
- ChatAgent · Consumer-facing orchestration boundary.
src/ailive/agent/chat_agent.py - Agent base and types
src/ailive/agent/base_agent.py - Context assembly · Combines personas, history, graph results, and memory rankings.
src/ailive/agent/chat_agent.py - Tool adapters · Default tools and custom Python callable support.
src/ailive/agent/llm_api/tools.py
Persistent memory
- MemCore package
src/ailive/MemCore/__init__.py - MemCore stream · Timestamped entity occurrences.
src/ailive/MemCore/memcore_stream.py - Entity knowledge store · Per-entity count and most-recent reference.
src/ailive/MemCore/entity_knowledge_store.py - Memory types
src/ailive/MemCore/types.py - Demo state files · Stream, entity store, and prior chat are file-backed.
MemCore_app/data/MemCore_stream.json
Knowledge retrieval
- Entity extraction · Extracts learned entities for graph writeback.
dev/recursive_retrieval/entity_extraction/entity_extraction.py - Graph retrieval · Identifies query entities and retrieves bounded related context.
dev/recursive_retrieval/langchain_retrieval/retrieve.py - Local graph/vector artifacts · Serialized doc, graph, and vector-store experiments.
dev/KG_mecore_stream/storage_graph/ch1_2_3_4/docstore.json
Models and services
- LLM runtime adapters · Local Ollama default with OpenAI alternatives.
src/ailive/agent/llm_api - External services · Neo4j graph backend plus search and domain APIs.
Other components
- Demo application · Stateful demonstration entry point.
MemCore_app/MemCore_app.py
Connections 21
- Demo application → ChatAgent: uses
- ChatAgent → Agent base and types: implements
- ChatAgent → Context assembly: assembles
- ChatAgent → Tool adapters: invokes
- ChatAgent → LLM runtime adapters: generates with
- ChatAgent → MemCore package: reads and updates
- Context assembly → Demo state files: loads history
- Context assembly → Entity knowledge store: uses rankings
- MemCore stream → Entity knowledge store: aggregates into
- MemCore package → MemCore stream: records
- MemCore package → Entity knowledge store: maintains
- MemCore package → Memory types: uses
- MemCore stream → Demo state files: persists
- Entity knowledge store → Demo state files: persists
- ChatAgent → Graph retrieval: retrieves context
- Graph retrieval → External services: queries graph backend
- Graph retrieval → Local graph/vector artifacts: experiments with
- ChatAgent → Entity extraction: writes responses back
- Entity extraction → MemCore stream: records entities
- Entity extraction → External services: updates graph
- Tool adapters → External services: calls optional APIs