soulpolicy-langgraph
5 行给你的 LangGraph agent 加漂移监测。
安装
pip install soulpolicy soulpolicy-langgraph
用法
from langgraph.graph import StateGraph, END
from typing import TypedDict
from soulpolicy import Client
from soulpolicy_langgraph import drift_check_node, should_block_on_drift
class State(TypedDict, total=False):
messages: list
drift: dict | None
sp = Client(api_key="sk_live_xxx")
graph = StateGraph(State)
graph.add_node("agent", my_agent_step)
graph.add_node("drift", drift_check_node(sp, baseline="bl_xxx"))
graph.set_entry_point("agent")
graph.add_edge("agent", "drift")
graph.add_conditional_edges(
"drift",
should_block_on_drift("warn"), # 路由谓词
{"continue": "agent", "block": END},
)
5 行:1 个 client,1 个 node,1 个谓词,2 条边。其余照常写。
文本提取
默认从 state["messages"] 取最后一条 AI/assistant 消息。也支持 state["output"] / state["last_message"] 字符串。要自定义:
graph.add_node("drift", drift_check_node(
sp,
baseline="bl_xxx",
state_text=lambda s: s["agent_reply"],
))
失败容忍
drift_check_node(sp, baseline="bl_xxx", on_error="skip")
# 调用失败时写入 state["drift"]=None + state["drift_error"]=str(e)
# 默认 "raise" 让 LangGraph retry/handle
路由
should_block_on_drift("warn") —— severity ≥ warn 路由到 "block"。可改:
should_block_on_drift("critical", continue_target="next", block_target="rollback")
Metadata
Release files for soulpolicy-langgraph 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| soulpolicy_langgraph-0.2.0.tar.gz | 9.3 kB | Without provenance | Details for soulpolicy_langgraph-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| soulpolicy_langgraph-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for soulpolicy_langgraph-0.2.0-py3-none-any.whl |
Total release size: 18.2 kB
Release files / soulpolicy_langgraph-0.2.0.tar.gz
| Download URL | soulpolicy_langgraph-0.2.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2cababda32bda0dc42aed82e42cfa86b3d9a0a016f4202eb57e0f66161d12369
|
|
BLAKE2b-256 checksum How to use checksums |
fa0630f25011aa97732fb1b6c1c2ce9a866606535bea8eed7df6ea95c7858a58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / soulpolicy_langgraph-0.2.0-py3-none-any.whl
| Download URL | soulpolicy_langgraph-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69d2a84e45971fae4e1cb40c544bdc461d1cbc37a04b6cb0eaccd9e1aa90b52b
|
|
BLAKE2b-256 checksum How to use checksums |
30883783350630935a5b240975819bc9ec59bd8f2fb9136d3a758e127a391d89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for soulpolicy-langgraph 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.