Skip to main content

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.

Metadata

Release files for langchain-deepsigma 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-deepsigma 0.1.0
File Size Uploaded
langchain_deepsigma-0.1.0.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-deepsigma 0.1.0
File Interpreter ABI Platform
langchain_deepsigma-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / langchain_deepsigma-0.1.0.tar.gz

Download URL langchain_deepsigma-0.1.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
36b8253551ce91612cc5df5956c42039dab9e4ff3b99f423b614a91c8dd3ab19
BLAKE2b-256 checksum
How to use checksums
e352602fb65cff8042a73a9fed4aeb97a9399033494dffdd2082f2b1d5320294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release files / langchain_deepsigma-0.1.0-py3-none-any.whl

Download URL langchain_deepsigma-0.1.0-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d1f14b499d622830df04bca2127c274d20b22453f56fef60ea445b4baaaf4ce
BLAKE2b-256 checksum
How to use checksums
c63a8bbf5f8252e7379bad982cdcf67ddf6c59a531eb54221197f180439767af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page