Repository navigation
Releases
v1.7LEMA2.0
1.Runtime agent separated
New file: MainCore/MainRuntime.py
Most of the run_agent_turn() functionality has been moved from statecore.py to a separate file. The new runtime manages tool invocation, mandatory tool status, retries, fallbacks, and model invocation for the final response.
2.Recovery system when a tool fails
New files: core/DynamicCallingToolFallback.py and core/mfallcom.py
When the main model fails to execute a mandatory tool, the new version can instruct the SUM model to generate JSON arguments, validate those arguments, and then attempt to run the tool. If this fails, the runtime attempts another listed fallback.
3.Memory system restructured
The direction of the changes is clear: active memory management, archiving and memory retrieval have been made more fault-tolerant and better controlled.
New Update
Active memory: Scans a subset of the most recent memory within a scan limit
Archive: Archiving takes place once the summary has been successfully saved
Token budget: Selects memory to retain based on relevance and token budget
Long-term retrieval: Combines lexical search, FAISS, confidence, support count, and recency
FTS5 index: Repairs missing index rows and cleans up orphaned references
FAISS: Retrieval failures are handled so that the SQLite path remains usable
Dynamic Calling Tool: Fixing and adding fallback to any tool using @require_each_turn (usage for json type data to process) by using sum model for fallback to completion the answer (Note: using same model can decrease the Latency, by write sum and main with same model in "conf.json")
When use @require_each_turn:
make sure it end with:
# If succeeded
return{"success": True,}and make sure to make "success": False when it failed as exception. if error or false, or either model wont call it, then it will fallback automatically to sum model to process it. and if there any error, the runtime should be not take down or crash, it will keep it alive.
and this update scored regression memory test with 49/50 then with test 2 141/150, around 98%~94% success recall
Warning
More @require_each_turn tools usage, can increase the latency.
v1.6.2 LEMA1.2
adding using Ranking model, and fix some bug commit memory issue (that's happened because AI can sometimes give the confident score in argument, and that's bad) less commit memory issue and had been tested got scored 47/50 (3 recall succeeded but the tested not accept the sum answer, i check it and the answer is still relevant and i score it for relevant context 50/50) in the LEMAv1.1 it got 2 failed because memory commit issue, now the recall memory become more active and active memory become more efficient, yet this still experimental, if there any issue, please let me know
ranking model using cross-encoder/mmarco-mMiniLMv2-L12-H384-v1
note to turn on persona, you can download the new statecore.py to MainCore folder, there you got the consistent Persona without making noise to memory
v1.6.1 LEMA v1.1
Update memory system.
This update focus on Active memory management (Prompt management), and has been tested with memory regression test.
and got scored:

96% Succeeded without make the Active memory full, it is work and reduce chance "ERRORr:400 Max Length" with this new memory system it keep the persistence memory and keep the Active memory efficient.
here some proof the active work (Prompt) still efficient yet the memory still persistence:

future plan: using reranking model to LEMAv1.2
LAPAIv1.6
This still work with 1.5 series because the modular system.
This update has 2 thing updated
-> Dynamic Calling Tools
Simplified user to use Calling Tools feature from AI:
to add just by add your function calling tools at MainCore/core/tools, then done the core will automaticly detect it and register it, no need hardcoded everything either add block of code or new file .py, all is work, example:
def get_time() -> str:
#with this \/ AI can have the description of tools
"""
Get the current system date and time.
"""
#here you can have your function here
return datetime.now().astimezone().isoformat()So i didn't add just that, you doesn't need to hardcoded everything as i say here some addons function hardcoded generic contract:
1.
@required_each_turnexample:
def memory_commit(kind: str, category: str, confidence: float):
"""
@required_each_turn
"""the engine will make:
required_tools = {
"memory_commit"
}So even tool ranking give memory_commit score = 0.05 The tool is still considered mandatory
2.
@requires_stateexample:
def recallmemory():
"""
@requires_state: memory_query
"""this tool doesn't mean it is mandatory to recall,
it is just say "this tool can work if X function is available" , here the example with the tool up there:
for example the state is:
context_state = {}then query memory is nothing
which is
recallmemory
eligible = Falseif the state become:
context_state = {
"memory_query": True
}then
recallmemory
eligible = True
3.
@provides_stateThe tool is a state that can be produced by the tool.
example:
def memory_commit(...):
"""
@provides_state: memory_query
"""then the tool return:
{
"success": True,
"_state": {
"memory_query": True
}
}engine will see contract;
memory_commit
provides → memory_query
then take:
context_state["memory_query"] = Trueand now that state can be use for next tools.
4.
@required_when_stateIf a particular state is active, this tool changes from simply being eligible to be mandatory to execute.
example:
def recallmemory():
"""
@requires_state: memory_query
@required_when_state: memory_query
"""when context_state = {}
the result
eligible = False
required = False
then when:
context_state = {
"memory_query": True
}the result :
eligible = True
required = True
-> new memory system
next the most exhausted update, the memory system
it is working directly at the core so, i will explain.
This memory try to achive: reducing Noise information with catagory system working with new tools system, so firs it will classification the information and commit with tools calling then reinforcement/update the information and retrieval.
it will detect the information that have same record, then in the future that information either got called or updated, the design took me a whole day to make it but so far:
existing memory
↓
support_count += 1
last_seen = now
so support count will be added and that is called reinforcement
But why is it important?
example:
data1:
Memory A
support = 8
confidence = 0.95
vs
data2
Memory B
support = 1
confidence = 0.60
data1 will have more repetitions that supporting.
Then when ranking:
retrieval
+
relation
+
confidence
+
support
The memory that is constantly reinforcement can have a better position.
But support_count does not mean that the fact is automatically true. It's just one of the signals.
i think again what if the information is changed?
example:
My favorite food is Burger.
then in future:
My favorite food is sushi now.
system should not thought Burger is wrong automaticly.
it have evidence with:
first_seen
last_seen
support_count
confidence
Then the retrieval/resolution uses time and score to determine the candidate who is more relevant.
This is important because the two of that information can be right at wrong time.
so i really thinking very long time to design like what is making the information relevant, it is "time"
So last_seen have big function, for example:
Burger
first_seen = January
last_seen = March
Sushi
first_seen = August
last_seen = September
when query the retrieval will sort as time relation.
new candidate got relation = 1.0 and next candidate relation = 0.995
then: 0.990 0.985
So memory updates not only update support_counts, but also update historical positions through last_seen.
(Actually i think how exactly human to remember, like processing new information etc, more likely self reflection)
then what is the different in between Update and decay
Long-term memory
example:
support_count = 5
confidence = 0.95
last_seen = ...
This memory is not lost just because time passes at the prompt.
Active Memory
If the memory or conversation goes to the active prompt relation = 1.0
after >3min relation -= 0.005 (still hardcoded for compability issue, in case you want to change, you can change it by yourself)
so:
PROMPT RELATION
→ decay
LONG-TERM MEMORY
→ persistent
Question is keep noted too.
it is classified the information as question.
So the system still knows that the question has ever happened, but it doesn't make it a fact.
This is what reduces noise.
after memory updated, FTS is maintenance too
New memory or updated memory goes to the long-term memory index:
long_term_memories
↓
FTS
When the user asks:
What is my favorite word?
retrieval search on:
Long_term memory
Not the entire chat history.
The result can:
[1]
Kind=preference
category=favorite_word
relationship = 0.0095
confidence = 0.95
Support = 1
Evidence:
My fav word is The fallen sky bring the truth of the lies
This is most important: the Update is not just by similiarity.
Lexically/semantic, but not the same fact.
thats why the plot is:
retrieval candidate
↓
kind
↓
category
↓
normalized evidence / duplicate check
↓
same memory?
├── yes → reinforce existing
└── no → create new
So, the lifecycle of a single memory looks like this:
For example:
2026-09-01
"I like Burger."
becomes:
support=1
confidence=0.95
first_seen=Sep 1
last_seen=Sep 1
Then:
2026-09-15
"I still like burger."
can reinforce the same evidence, depending on the classification/duplicate resolution result:
support=2
last_seen=Sep 15
and:
2026-09-20
"My favorite food is sushi now."
becomes a new candidate:
burger
support=2
last_seen=Sep 15
sushi
support=1
last_seen=Sep 20
Retrieval then has access to historical information, not just the most recent string.
Expected Regression Test:

LAPAI1.5.2
Adding Regression Test and Tracing, mostly fixing Memory retrieval work, not to worry it is compatible with 1.5 version series
make sure it run on LAPAI env
To use Regression test
After Installation you can directly run trunstrict.py
python trunstrict.py --stress
To use Tracing
At MainCore you will found traceL.py that need to be running first to run Live Trace and it is muss be run before next step to tracing
next step is just run your core with tr.py, for example i using quick test run ai with fp function:
python tr.py qtrunaicfp.py2026-09-25.03-16-08.mp4
Planning for future update, adding calling tools
thankyou for all your suggestion!
LAPAI Simplifier update
Make the deployment more simple
Make the more, for example you make in another project:
from MainCore import runcorefp as c
c.initialize_core()
print(c.Main_Core_FP_Function('halo'))will perfectly fine and work in another directory
and shortcut command activate LAPAI-env
just run in console after installation:
ndand it will show (LAPAI-env) ./.../user/directory:
to delete or remove shortcut, run uinsShortcut.sh/bat as your os.
Modular, Configurable, build with simple cache system
you can anything on Settings/conf.json
and you can add or change the value as you like with new simple json GUI " jsonEd ", it will installed when you run autoinstaller known as "autod.sh/bat"
LAPAIv1.5
MODULAR SYSTEM UPDATE v1.5
linux support, so can windows and linux now.
Changelog
[1.5] — Modular
Added
- Added persistent memory state management through SQLite.
- Added time-based memory compaction with summary checkpoints.
- Added
memory_statetracking using timestamps and messagerowid. - Added dynamic memory prompt construction through
build_memory_prompt(). - Added persona loading through
load_persona(). - Added context budget calculation through
calculate_context_budget(). - Added embedding normalization for consistent vector retrieval.
- Added embedding dimension and FAISS index validation.
- Added backward-compatible handling for older memory databases.
- Added more detailed memory metadata including timestamps, importance, session IDs, and retrieval scores.
Changed
- Changed the embedding model from
all-mpnet-base-v2tomultilingual-e5-small. - Changed embedding dimension from
768to384. - Changed ONNX execution provider from
DmlExecutionProvidertoCPUExecutionProvider. - Changed embedding generation to support
queryandpassageprefixes for E5-style retrieval. - Changed token estimation from word-based counting to tokenizer-based token counting.
- Changed FAISS retrieval from
IndexFlatL2distance-based retrieval to normalizedIndexFlatIPsimilarity retrieval. - Changed FAISS similarity handling to use normalized cosine-style similarity.
- Changed FTS5 score normalization to properly handle negative BM25 values.
- Changed recent-memory retrieval from a global hour-based lookup to session-specific minute-based memory retrieval.
- Increased relevant-memory retrieval from a default of 5 results to 10 results.
- Changed memory ranking to combine FTS relevance, semantic similarity, importance, recency, and role weighting.
- Changed summarization from message-count-based summarization to time-based memory compaction.
- Changed the main pipelines to build memory context through a dedicated memory prompt builder.
- Changed persona injection to use a dedicated loader instead of reading the persona file directly inside the main functions.
- Changed model configuration paths and runtime API endpoint handling.
- Changed error handling so model/runtime failures can return an explicit error result.
Improved
- Improved FAISS initialization by detecting embedding dimension mismatches.
- Improved FAISS consistency checks between the index and memory map.
- Improved embedding quality handling through attention-mask-aware mean pooling.
- Improved memory retrieval by combining lexical and semantic search into a single scoring pipeline.
- Improved prompt trimming so it can act as an emergency fallback instead of being the primary memory-management mechanism.
- Improved compatibility with existing databases through memory-state migration support.
- Improved separation between active memory, persistent summaries, recalled memory, and learned knowledge.
Removed / Replaced
- Replaced the old
load_history()andget_recent_history()flow. - Replaced the old count-based
summarize_session()implementation withcompact_old_memory(). - Replaced direct JSON history compaction with persistent memory-state tracking in SQLite.
- Removed the previous Ollama fallback logic from the fast-response pipeline.
- Replaced the previous L2-to-similarity conversion inside FAISS retrieval with normalized inner-product retrieval.
LAPAI Update v1.4
This update make Ollama can work at this project, adding UI to quick settings and adding XTTS support
Tutorial How to Install:
Download LAPAIv.1.4.7z from here at Assets
Tutorial.mp4
1. Install Pyton3.10
2. Run AutoDownloadALL.bat
3. Wait until done, and you all set
How to set:
2026-04-15.23-26-17.mp4
Set XTTS can using another or customize sound sample
Set UI settings app to set quick settings
Testing Memorial
Run API to get engine API
For example using it in another program
note: Make sure for LemonadeServer it using port 8000 and for Ollama using port 11434
CHANGELOG
Memory System
Fixing and Improving:
-Importance
-Recency Decay
-Role Weighting
Change From Search to Ranking System
FAISS Metadata Upgrade
-Tracking Time
-Can use old data memory from v1.3
Importance Scoring System
Smart Recall Decision (AI Based) #still in progress
Learning System More Separate & Clear
Thought Extraction Layer
Token System Management
multi Backend support (Ollama)
Support XTTS (New)
Settings UI Model name, persona (New)
Simplified the installing
LAPAI Update Feature v1.3.2
Finally i had some time like 2-3 days off, so i make it, this update bring connected from offline AI to Arduino or hardware and AI will who the one control the arduino hardware, AI will decide or something like that. let me tell how this work.
AI decided what user want to do
From start you need activated ArdCmd.py to get able AI to command Arduino, so from here after that the main program is in AItoardn.py but before you run the main program you need upload or modified on my program template for Arduino Ardn.ino okay after that upload to arduino. and now you are able to run main program. and good luck to experiment with it. for example here im gonna use oled for output text and led for output led.
LAPAI v1.3.1
Adding new program for AI command to GameEngine, now you are able give a command based from user input, and completely offline, detail file you can see at Core file, there has GDAPIND.py for processing command to Json, and program template file named GameDevelopmentCommandAITemplate.cs for template script to processing Data from GDAPIND.py from AI
detail files on this repo at folder LAPAI\Core