Skip to main content

Human-in-the-loop approval gates for LangChain agents via Sologate

Project description

sologate-langchain

Human-in-the-loop approval gates for LangChain agents.

When your agent is about to do something risky — delete files, send bulk email, make API calls — Sologate pauses it and routes the action to a human for approval. One approve/reject click. Full audit trail. Agent resumes automatically.

pip install sologate-langchain

3-line integration

from sologate_langchain import SologateCallbackHandler

handler = SologateCallbackHandler(
    sologate_url="https://www.sologate.app",
    api_key="at_your_key_here",
)

agent_executor = AgentExecutor(agent=agent, tools=tools, callbacks=[handler])

That's it. Every tool call is scored automatically. Low-risk actions pass through silently. High-risk actions pause your agent and open an approval request in the Sologate Decision Center.


How it works

Agent calls tool
      ↓
SologateCallbackHandler.on_tool_start()
      ↓
Risk score 0–100 calculated locally (no API call for low-risk)
      ↓
score < threshold (60)?  →  runs silently ✓
score ≥ threshold?       →  POST /api/agent/request-approval
                              ↓
                         Agent PAUSES (WebSocket wait)
                              ↓
                    Human approves/rejects in dashboard
                              ↓
                    Approved → agent continues ✓
                    Rejected → GateRejectedError raised ✗

Full example

import os
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.tools import ShellTool, WriteFileTool
from langchain import hub
from sologate_langchain import SologateCallbackHandler

llm = ChatOpenAI(model="gpt-4o")
tools = [ShellTool(), WriteFileTool()]
prompt = hub.pull("hwchase17/react")

agent = create_react_agent(llm, tools, prompt)

handler = SologateCallbackHandler(
    sologate_url=os.environ["SOLOGATE_URL"],
    api_key=os.environ["SOLOGATE_KEY"],
    threshold=60,  # gate anything scored ≥ 60/100
)

agent_executor = AgentExecutor(agent=agent, tools=tools, callbacks=[handler])
result = agent_executor.invoke({"input": "Clean up the project folder"})

When the agent tries rm -rf ./backups/ it scores 97/100 — HIGH and your terminal shows:

[sologate] 🔴 Gating: terminal (score 97/100 — HIGH)
[sologate] Reason: Shell command contains rm -rf (irreversible bulk deletion)
[sologate] Flags:  • rm -rf detected
[sologate] Waiting for human decision at https://www.sologate.app/decisions...

Approve in the dashboard → agent continues. Reject → GateRejectedError raised.


Environment variables

export SOLOGATE_URL=https://www.sologate.app
export SOLOGATE_KEY=at_your_key_here

Or pass directly to SologateCallbackHandler(sologate_url=..., api_key=...).


Risk scoring

Scores are calculated locally — no network round-trip for safe actions.

Score Tier Examples
90+ HIGH rm -rf, DROP TABLE, curl | sh
76–89 HIGH sudo, --force, credential file writes
60–75 HIGH Bulk email, HTTP DELETE, force push
30–59 MEDIUM Shell exec, file writes, outbound messages
0–29 LOW Read operations, searches — auto-approved

Customize the threshold:

handler = SologateCallbackHandler(..., threshold=80)  # only gate HIGH risk

Low-level gate function

For custom agent frameworks (not LangChain):

from sologate_langchain import gate, GateRejectedError

try:
    gate(
        "delete_customer_records",
        sologate_url="https://www.sologate.app",
        api_key="at_...",
        context="Agent is about to delete 312 inactive customer records",
        payload={"count": 312, "table": "customers"},
    )
    # human approved — proceed
    db.execute("DELETE FROM customers WHERE status='inactive'")

except GateRejectedError:
    print("Rejected — no records deleted")

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sologate_langchain-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sologate_langchain-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file sologate_langchain-0.1.0.tar.gz.

File metadata

  • Download URL: sologate_langchain-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for sologate_langchain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c1d499d58dd56f1e7635ca2c08b8f99123da23325e7fdfc17906893364302442
MD5 006fae671e88e6117627261ae8bfc73a
BLAKE2b-256 ec796b3f0a6c76164c7c524dd91a7c2b4d479154cb49b176cdf997ec378f9266

See more details on using hashes here.

File details

Details for the file sologate_langchain-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sologate_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 184b0eed5ef74b4215e966f8051eec0ef4651fd9d8393a8d7b4a9970b158fa26
MD5 13e1c4614d24612ce7063b308e425935
BLAKE2b-256 a29b5ff3efeeb47adba7090690fcf486e5480bba7f137d8c167b5c1f6ae66461

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page