LangChain integration for Σ OVERWATCH — governed, auditable LangChain chains and agents
Project description
langchain-deepsigma
LangChain integration for Σ OVERWATCH — governed, auditable LangChain chains and agents.
Every chain run becomes a sealed Decision Episode recorded through the full DLR / RS / DS / MG governance pipeline.
Install
# 1. Install the parent deepsigma package first
pip install -e /path/to/DeepSigma-v0.3.0
# 2. Install this package
pip install -e /path/to/DeepSigma-v0.3.0/packages/langchain-deepsigma
Three Integration Surfaces
1. Callbacks — Automatic Governance
Drop DeepSigmaCallbackHandler into any chain or agent. Every run is automatically
wrapped in a sealed Decision Episode.
from langchain_deepsigma import DeepSigmaCallbackHandler
handler = DeepSigmaCallbackHandler(decision_type="CustomerSupportChain")
# Use with any LangChain chain
result = chain.invoke(
{"input": "What is the refund policy?"},
config={"callbacks": [handler]},
)
# After the run, governance artifacts are available:
print(handler.episode) # sealed episode dict
print(handler.dlr.to_dict_list()) # Decision Log Records
print(handler.rs.summarise()) # Reflection Session summary
print(handler.ds.summarise()) # Drift signals (if any errors occurred)
print(handler.mg.node_count) # Memory Graph node count
2. Tools — Governance as Agent Capabilities
Give your agent the ability to query its own governance state.
from langchain_deepsigma import deepsigma_tools, DeepSigmaCallbackHandler
handler = DeepSigmaCallbackHandler()
chain.invoke(..., config={"callbacks": [handler]})
# Wire the post-run governance state to tools
tools = deepsigma_tools(mg=handler.mg, dlr=handler.dlr)
# Bind to an agent
agent = create_tool_calling_agent(llm, tools, prompt)
Available tools:
| Tool | Name | What it does |
|---|---|---|
IRISQueryTool |
iris_query |
WHY / WHAT_DRIFTED / STATUS / RECALL / WHAT_CHANGED |
CoherenceScorerTool |
coherence_score |
Score episodes 0–100 (A–F) |
AuditTool |
coherence_audit |
Cross-artifact consistency audit |
ReconcilerTool |
coherence_reconcile |
Detect inconsistencies, propose repairs |
# Use tools individually
from langchain_deepsigma import IRISQueryTool, CoherenceScorerTool
import json
iris = IRISQueryTool(mg=handler.mg)
print(iris._run(query_type="STATUS"))
# [IRIS STATUS] Status: RESOLVED
# Summary: Health: green. No drift detected. Claims: 3.
scorer = CoherenceScorerTool()
print(scorer._run(episodes=json.dumps(episodes)))
# Coherence Score: 91.2/100 Grade: A
# Dimensions:
# policy_adherence 95.0 (weight 25%)
# outcome_health 88.0 (weight 30%)
# ...
3. Memory — Decision History in Prompts
Use the Memory Graph as a LangChain memory provider.
from langchain_deepsigma import DeepSigmaMemory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
memory = DeepSigmaMemory(top_k=5)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant. Here is relevant decision history:\n{decision_history}"),
("human", "{input}"),
])
chain = prompt | llm
# Each turn:
history = memory.load_memory_variables({"input": user_input})
response = chain.invoke({"input": user_input, **history})
memory.save_context({"input": user_input}, {"output": response.content})
Share a Memory Graph between handler and memory
from coherence_ops import MemoryGraph
shared_mg = MemoryGraph()
handler = DeepSigmaCallbackHandler()
handler.mg = shared_mg
memory = DeepSigmaMemory(mg=shared_mg)
# Now both the chain's episodes AND saved memory turns live in one graph
Full Example
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_deepsigma import DeepSigmaCallbackHandler, DeepSigmaMemory, deepsigma_tools
llm = ChatOpenAI(model="gpt-4o-mini")
memory = DeepSigmaMemory(top_k=3)
prompt = ChatPromptTemplate.from_messages([
("system", "Decision history:\n{decision_history}"),
("human", "{input}"),
])
chain = prompt | llm
for user_input in ["What's the plan?", "Confirm deployment", "Roll back if needed"]:
handler = DeepSigmaCallbackHandler(decision_type="OpsDecision")
history = memory.load_memory_variables({"input": user_input})
response = chain.invoke(
{"input": user_input, **history},
config={"callbacks": [handler]},
)
memory.save_context({"input": user_input}, {"output": response.content})
print(f"Grade: {handler.dlr.to_dict_list()[0].get('outcomeCode', 'N/A')}")
Tests
cd /path/to/DeepSigma-v0.3.0
pytest packages/langchain-deepsigma/tests/ -v
Package Structure
langchain-deepsigma/
├── pyproject.toml
├── README.md
├── langchain_deepsigma/
│ ├── __init__.py # Public exports
│ ├── callbacks.py # DeepSigmaCallbackHandler
│ ├── tools.py # Four governance tools + deepsigma_tools()
│ └── memory.py # DeepSigmaMemory
└── tests/
├── test_callbacks.py
├── test_tools.py
└── test_memory.py
Σ OVERWATCH — We don't sell agents. We sell the ability to trust them.
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_deepsigma-0.1.0.tar.gz.
File metadata
- Download URL: langchain_deepsigma-0.1.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36b8253551ce91612cc5df5956c42039dab9e4ff3b99f423b614a91c8dd3ab19
|
|
| MD5 |
881ce719093ea1215192ecca0de5427b
|
|
| BLAKE2b-256 |
e352602fb65cff8042a73a9fed4aeb97a9399033494dffdd2082f2b1d5320294
|
File details
Details for the file langchain_deepsigma-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_deepsigma-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d1f14b499d622830df04bca2127c274d20b22453f56fef60ea445b4baaaf4ce
|
|
| MD5 |
ea496fcb29ae9d6f8ffb63aa24011ea0
|
|
| BLAKE2b-256 |
c63a8bbf5f8252e7379bad982cdcf67ddf6c59a531eb54221197f180439767af
|