diff --git a/README.md b/README.md index 502fc12..91dd19d 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -Demo of rewards +# System State Pipeline - Native Implementation + +## Architecture +This implementation rejects PR #52 to avoid additive dependency bloat. State synchronization and race condition mitigation (Issue #26) are handled via native Lua scripts executed at the data layer. + +## Requirements +- memanto-sdk +- langchain (Python) + +## Execution +1. Run Python ingestion to initialize state and execute LangChain tool: + `python3 full_pipeline_demo.py` +2. Run JS verification to prove cross-process persistence: + `node full_pipeline_demo.js` + +## Design Constraints +- Zero-dependency locking logic. +- Atomic transitions via Lua. +- Shared AGENT_ID namespace for ingestion and recall. diff --git a/full_pipeline_demo.js b/full_pipeline_demo.js new file mode 100644 index 0000000..533b29b --- /dev/null +++ b/full_pipeline_demo.js @@ -0,0 +1,24 @@ +const { SdkClient } = require('memanto-sdk'); + +async function verifyCrossProcessPersistence() { + const syncAgentId = 'sys_eng_prod_01'; + const persistenceClient = new SdkClient(); + + // Verify state written by Python process + const currentState = await persistenceClient.get(`${syncAgentId}:status`); + + const sessionConfig = { + syncAgentId, + timestamp: Date.now() + }; + + console.log(`Cross-process state verification: ${currentState}`); + + if (currentState === 'active') { + console.log('Persistence verified: State consistency maintained across processes.'); + } else { + process.exit(1); + } +} + +verifyCrossProcessPersistence().catch(console.error); diff --git a/full_pipeline_demo.py b/full_pipeline_demo.py new file mode 100755 index 0000000..d79f757 --- /dev/null +++ b/full_pipeline_demo.py @@ -0,0 +1,44 @@ +import os +from langchain.tools import Tool +from memanto.cli.client.sdk_client import SdkClient + +def execute_atomic_state_transition(agent_id, key, expected_val, new_val): + """ + Bypasses external locking libraries by executing a Lua script on the + data layer to ensure atomicity and prevent race conditions in #26. + """ + client = SdkClient() + lua_script = """ + local current = redis.call('GET', KEYS[1]) + if current == ARGV[1] then + redis.call('SET', KEYS[1], ARGV[2]) + return 1 + end + return 0 + """ + # Atomic operation performed at the server level to eliminate client-side sync bloat + return client.eval(lua_script, keys=[f"{agent_id}:{key}"], args=[expected_val, new_val]) + +def run_ingestion_cycle(): + sync_agent_id = "sys_eng_prod_01" + persistence_client = SdkClient() + + state_payload = "initialized" + persistence_client.set(f"{sync_agent_id}:status", state_payload) + + # Binding Memanto logic as a LangChain Tool to avoid plain text instruction reliance + state_tool = Tool( + name="AtomicStateUpdate", + func=lambda input_str: execute_atomic_state_transition( + sync_agent_id, "status", "initialized", input_str + ), + description="Updates the system state atomically" + ) + + result = state_tool.run("active") + print(f"Atomic transition result: {result}") + return sync_agent_id + +if __name__ == "__main__": + agent_id = run_ingestion_cycle() + print(f"Ingestion complete for AGENT_ID: {agent_id}")