OpenBox governance and observability SDK for LangChain
Project description
OpenBox LangChain SDK — Python
Governance and observability SDK for LangChain agents. Intercepts agent execution via AgentMiddleware to enforce OpenBox policies, guardrails, HITL approval flows, and hook-level governance (HTTP/DB/File I/O).
Installation
pip install openbox-langchain-sdk-python
Quick Start
from langchain.agents import create_agent
from openbox_langchain import create_openbox_langchain_middleware
# 1. Create middleware
middleware = create_openbox_langchain_middleware(
api_url="https://core.openbox.ai",
api_key="obx_live_...",
agent_name="MyAgent",
)
# 2. Create agent with middleware
agent = create_agent(
model="openai:gpt-4o",
tools=[...],
middleware=[middleware],
)
# 3. Invoke — governance applied automatically
result = agent.invoke({"messages": [("user", "your query")]})
How It Works
Three-layer governance architecture:
| Layer | Mechanism | Governs |
|---|---|---|
| 1 | AgentMiddleware hooks | Agent lifecycle (before/after), model calls, tool execution |
| 2 | Hook Governance | HTTP requests, DB queries, file I/O at kernel boundary |
| 3 | Activity Context Mapping | Links hook traces to governance activities via OTel |
Middleware hooks:
before_agent/abefore_agent— Session setup, pre-screen guardrailswrap_model_call/awrap_model_call— LLM interception, PII redactionwrap_tool_call/awrap_tool_call— Tool governance, OTel span registrationafter_agent/aafter_agent— Session cleanup
Configuration
middleware = create_openbox_langchain_middleware(
api_url="https://core.openbox.ai", # OpenBox Core URL
api_key="obx_live_...", # API key (obx_live_* or obx_test_*)
agent_name="MyAgent", # Agent name (from dashboard)
governance_timeout=30.0, # HTTP timeout in seconds
validate=True, # Validate API key on startup
session_id="session-123", # Optional session tracking
sqlalchemy_engine=engine, # Optional DB governance
tool_type_map={ # Optional tool classification
"search_web": "http",
"query_db": "database",
},
)
Supported Agent Types
create_agent(model, tools, middleware=[...])— recommended- Any LangChain agent builder that accepts
middleware
Verdict Enforcement
5-tier verdict system:
- ALLOW — Request permitted
- CONSTRAIN — Request constrained (e.g., rate limit)
- REQUIRE_APPROVAL — Human approval required (HITL polling)
- BLOCK — Request blocked with error
- HALT — Entire workflow halted (unrecoverable error)
Requirements
- Python 3.11+
- LangChain >= 0.3.0
- LangGraph >= 0.2.0
- openbox-langgraph-sdk-python >= 0.1.0
API Reference
Primary factory:
create_openbox_langchain_middleware()— Creates configured middleware
Re-exported from langgraph SDK:
enforce_verdict()— Enforce verdictspoll_until_decision()— HITL approval pollingGovernanceClient,GovernanceConfig— Core types
See openbox_langchain.__init__.py for full API export list.
License
MIT
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 openbox_langchain_sdk_python-0.1.0.tar.gz.
File metadata
- Download URL: openbox_langchain_sdk_python-0.1.0.tar.gz
- Upload date:
- Size: 165.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae12ca7b778bf26e233417cc197e21c72488144aeaa7e0c948ab540ce9062cee
|
|
| MD5 |
844b2abf90b8b4202bc2705d11d08509
|
|
| BLAKE2b-256 |
0668ca38560dad1929b4cc6378a5c0dfa297ccbd4636f2e583a5244aa4beb5b1
|
Provenance
The following attestation bundles were made for openbox_langchain_sdk_python-0.1.0.tar.gz:
Publisher:
publish.yml on OpenBox-AI/openbox-langchain-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openbox_langchain_sdk_python-0.1.0.tar.gz -
Subject digest:
ae12ca7b778bf26e233417cc197e21c72488144aeaa7e0c948ab540ce9062cee - Sigstore transparency entry: 1200176057
- Sigstore integration time:
-
Permalink:
OpenBox-AI/openbox-langchain-sdk-python@58a97ccb434235957169e4996dc12bbf4df8d5ce -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/OpenBox-AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@58a97ccb434235957169e4996dc12bbf4df8d5ce -
Trigger Event:
push
-
Statement type:
File details
Details for the file openbox_langchain_sdk_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openbox_langchain_sdk_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b4e9c495f1637efb21b81dd691e1c96d37911741d12dbcf4f12327c82935dce
|
|
| MD5 |
628938fe27edce2ccc27d4cb915f59fc
|
|
| BLAKE2b-256 |
597e578e7a950c31b916c167d73a834d5c1a1a8036864545d4ad409f675c4d1d
|
Provenance
The following attestation bundles were made for openbox_langchain_sdk_python-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on OpenBox-AI/openbox-langchain-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openbox_langchain_sdk_python-0.1.0-py3-none-any.whl -
Subject digest:
9b4e9c495f1637efb21b81dd691e1c96d37911741d12dbcf4f12327c82935dce - Sigstore transparency entry: 1200176080
- Sigstore integration time:
-
Permalink:
OpenBox-AI/openbox-langchain-sdk-python@58a97ccb434235957169e4996dc12bbf4df8d5ce -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/OpenBox-AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@58a97ccb434235957169e4996dc12bbf4df8d5ce -
Trigger Event:
push
-
Statement type: