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
Release files for langchain-sgraal 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_sgraal-0.1.0.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_sgraal-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.2 kB
Release files / langchain_sgraal-0.1.0.tar.gz
| Download URL | langchain_sgraal-0.1.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90be31e9942a13944988abb4f73f1e55ab303e52506ccf2e86635de63b505a9f
|
|
BLAKE2b-256 checksum How to use checksums |
5d8b96beae789147d9f44997f129819c8f889ed625650df641a4d90f98769639
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / langchain_sgraal-0.1.0-py3-none-any.whl
| Download URL | langchain_sgraal-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c062b83452356635452a1e31df7ee93125914fbdb82d3a4c88f6c26fd0eafc15
|
|
BLAKE2b-256 checksum How to use checksums |
1bf21aa885d08df48adbd839b0947345bf8ffaba7e7d67b773c14ae5ecb32424
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|