LangChain integration for Sgraal memory governance protocol
Project description
langchain-sgraal
LangChain integration for the Sgraal memory governance protocol.
Install
pip install langchain-sgraal
Quick Start
As a LangChain Tool
from langchain_sgraal import SgraalMemoryGuard
tool = SgraalMemoryGuard(api_key="sg_live_...")
result = tool.invoke({
"memory_state": [{
"id": "mem_001",
"content": "User prefers metric units",
"type": "preference",
"timestamp_age_days": 45,
"source_trust": 0.9,
"source_conflict": 0.2,
"downstream_count": 3,
}],
"action_type": "irreversible",
"domain": "fintech",
})
print(result)
# "SAFE (Ω=12.4): Memory is reliable. Proceed."
# or "BLOCKED (Ω=82.1): High risk. Do NOT proceed."
Use in a LangChain Agent
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from langchain_sgraal import SgraalMemoryGuard
llm = ChatOpenAI(model="gpt-4")
tools = [SgraalMemoryGuard(api_key="sg_live_...")]
agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS)
agent.run("Check if the user's address memory is still reliable")
Guard Decorator for LangGraph Nodes
from langchain_sgraal import sgraal_guard
@sgraal_guard(
memory_state=lambda state: state["memories"],
action_type="irreversible",
domain="fintech",
block_on="BLOCK",
)
def process_trade(state):
return {"result": execute_trade(state)}
with_preflight Wrapper
from langchain_sgraal import with_preflight
def trade_node(state):
return execute_trade(state)
safe_trade = with_preflight(
trade_node,
get_memory=lambda state: state["memories"],
action_type="irreversible",
domain="fintech",
)
Environment Variable
Set SGRAAL_API_KEY to avoid passing api_key everywhere:
export SGRAAL_API_KEY=sg_live_...
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_sgraal-0.1.0.tar.gz.
File metadata
- Download URL: langchain_sgraal-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90be31e9942a13944988abb4f73f1e55ab303e52506ccf2e86635de63b505a9f
|
|
| MD5 |
8a0404ec6f4032bb8d8fbd8bf3bf70c9
|
|
| BLAKE2b-256 |
5d8b96beae789147d9f44997f129819c8f889ed625650df641a4d90f98769639
|
File details
Details for the file langchain_sgraal-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_sgraal-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c062b83452356635452a1e31df7ee93125914fbdb82d3a4c88f6c26fd0eafc15
|
|
| MD5 |
0d3af445618784b904be1e3220bb47af
|
|
| BLAKE2b-256 |
1bf21aa885d08df48adbd839b0947345bf8ffaba7e7d67b773c14ae5ecb32424
|