Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions full_pipeline_demo.js
Original file line number Diff line number Diff line change
@@ -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);
44 changes: 44 additions & 0 deletions full_pipeline_demo.py
Original file line number Diff line number Diff line change
@@ -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}")