Csf¶
CSF — mvp.csf (v3.0.0)
Cluster: Safety & Alignment | Type: component | MCP Tools: 52
Overview¶
CrossLinkedSafetyFramework AIBlock that verifies a BoundedAgent against a safety epsilon bound and returns a SafetyDecisionReport. The SafetyVerifier inside supports two verification methods: union_bound (sum of per-hazard failure probabilities) and worst_case (maximum single-hazard probability). The block is used by Phase B+ components to gate LLM calls, file writes, and code execution with a formal safety verdict before proceeding.
When to use:
- Gating any high-risk operation with a formal safety check before execution
- Enforcing system-wide epsilon risk bounds on agents with known hazard profiles
- Integrating a lightweight safety layer into a pipeline without external SMT solvers
Example:
from mvp.csf import CSFBlock, SafetyQuery
from mvp.core import BoundedAgent
agent = BoundedAgent(name="robot_arm", hazard_probs={"collision": 0.02, "drop": 0.01})
block = CSFBlock(name="csf", default_epsilon=0.05)
result = block.infer(SafetyQuery(agent=agent, epsilon=0.05, method="union_bound"))
# result.value.approved → True/False; result.value.reason → explanation
Works well with: align_csf, align_specs, formal_methods
Optional formal backends
CSF's built-in union_bound and worst_case checks run without external solvers. The formal bridge can also call Z3, NuSMV, and Lean, but those backends are optional and may be unavailable or slow on a minimal install. When a backend is missing or times out, CSF returns verified=None with an explicit error/degradation message; treat that as "no proof from this backend", not as a pass.
Public API¶
CompositionResult¶
Result of compositional safety verification (Theorem 1).
| Field | Type | Default |
|---|---|---|
agent1_epsilon | float | required |
agent2_epsilon | float | required |
correlation_rho | float | required |
composed_success_lower | float | required |
composed_epsilon | float | required |
interface_compatible | bool | required |
resource_feasible | bool | required |
meets_bound | bool | required |
explanations | list[str] | field(default_factory=list) |
FormalCheckResult¶
Result of a formal verification check via an external backend.
| Field | Type | Default |
|---|---|---|
backend | str | required |
property_name | str | required |
verified | bool \| None | required |
counterexample | list[dict] \| None | None |
proof | str | '' |
duration_sec | float | 0.0 |
error | str | '' |
p_unsafe | float | 0.0 |
confidence_interval | tuple[float, float] | (0.0, 1.0) |
epsilon | float | 0.05 |
delta | float | 0.01 |
coverage | str | 'full' |
CSFBlock(AIBlock[SafetyQuery, SafetyDecisionReport, None])¶
CrossLinkedSafetyFramework as an AIBlock.
| Field | Type | Default |
|---|---|---|
name | str | 'csf' |
default_epsilon | float | 0.2 |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
diagnostics | list[str] | field(default_factory=list) |
Methods:
infer(data: SafetyQuery) -> Result[SafetyDecisionReport]¶
LTLAtom¶
Atomic proposition — leaf of the LTL formula tree.
| Field | Type | Default |
|---|---|---|
predicate | str | required |
LTLNot¶
Negation: ¬φ
| Field | Type | Default |
|---|---|---|
inner | LTLFormula | required |
LTLAnd¶
Conjunction: φ ∧ ψ
| Field | Type | Default |
|---|---|---|
left | LTLFormula | required |
right | LTLFormula | required |
LTLOr¶
Disjunction: φ ∨ ψ
| Field | Type | Default |
|---|---|---|
left | LTLFormula | required |
right | LTLFormula | required |
LTLNext¶
Next: X φ
| Field | Type | Default |
|---|---|---|
inner | LTLFormula | required |
LTLAlways¶
Always / Globally: □ φ (G φ)
| Field | Type | Default |
|---|---|---|
inner | LTLFormula | required |
LTLEventually¶
Eventually / Finally: ◇ φ (F φ)
| Field | Type | Default |
|---|---|---|
inner | LTLFormula | required |
LTLUntil¶
Until: φ U ψ
| Field | Type | Default |
|---|---|---|
left | LTLFormula | required |
right | LTLFormula | required |
LTLRelease¶
Release: φ R ψ (dual of Until)
| Field | Type | Default |
|---|---|---|
left | LTLFormula | required |
right | LTLFormula | required |
RollbackFeasibility¶
Result of Definition 5 rollback feasibility analysis.
| Field | Type | Default |
|---|---|---|
feasible | bool | required |
snapshot_interval | int | required |
required_interval | int | required |
rollback_delay_sec | float | required |
max_delay_sec | float | required |
irreversible_ops | frozenset[str] | required |
trust_boundary | frozenset[str] | required |
explanations | list[str] | field(default_factory=list) |
GitRollbackManager¶
Git-backed rollback manager for an isolated workspace.
| Field | Type | Default |
|---|---|---|
repo_path | str | required |
Methods:
snapshot(message: str = 'checkpoint') -> Result[str]¶
Stage all changes and create a commit.
rollback(commit_sha: str) -> Result[str]¶
Hard-reset the repository to commit_sha.
current_sha() -> Result[str]¶
Return the SHA of the current HEAD commit.
close() -> None¶
Release GitPython resources held by this manager.
check_feasibility(N: int, operations: list[str], max_delay: float = 60.0) -> RollbackFeasibility¶
Check rollback feasibility per Definition 5.
classify_operation(op: str) -> RiskClassification¶
Classify an operation's risk level using IRREVERSIBLE_OPS.
GameState¶
A single state in the safety game trace.
| Field | Type | Default |
|---|---|---|
agent_state | Any | required |
step | int | required |
violation_prob | float | required |
GameResult¶
Result of solving the 2-player safety verification game.
| Field | Type | Default |
|---|---|---|
verifier_wins | bool | required |
max_violation_prob | float | required |
per_property | list[dict] | field(default_factory=list) |
worst_input_sequence | list | field(default_factory=list) |
trace | list[GameState] | field(default_factory=list) |
explanations | list[str] | field(default_factory=list) |
LTLMonitor(SafetyMonitor)¶
Runtime safety monitor that tracks LTL formula satisfaction over a live trace.
Constructor:
| Parameter | Type | Default |
|---|---|---|
properties | list[LTLFormula] | required |
Methods:
reset() -> None¶
update(state: Any, inp: Any, hazard: float) -> None¶
is_violated() -> bool¶
trace() -> list[dict[str, bool]]¶
SafetyQuery¶
Input to CSFBlock — describes what to verify.
| Field | Type | Default |
|---|---|---|
agent | BoundedAgent | required |
epsilon | float | 0.2 |
method | Literal['union_bound', 'worst_case'] | 'union_bound' |
max_steps | int | 0 |
strategy | str | '' |
SafetyVerifier¶
Verifies whether a
BoundedAgentmeets an epsilon risk bound.
Constructor:
| Parameter | Type | Default |
|---|---|---|
epsilon | float | 0.2 |
Methods:
verify(agent: BoundedAgent, method: str = 'union_bound', epsilon: float | None = None) -> SafetyDecisionReport¶
CSFFormalMCPBlock(AIBlock[MCPCSFFormalInput, MCPCSFFormalOutput, dict])¶
26-op CSF Formal Methods MCP block.
| Field | Type | Default |
|---|---|---|
name | str | 'csf_formal_mcp' |
db_path | str | ':memory:' |
state | dict \| None | None |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(data: MCPCSFFormalInput) -> Result[MCPCSFFormalOutput]¶
MCPCSFFormalInput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | CSF_FORMAL_OPS | required |
formula_str | str | '' |
formula_id | str | '' |
trace | list[dict[str, bool]] | Field(default_factory=list) |
property_name | str | '' |
agent_states | list[str] | Field(default_factory=list) |
unsafe_states | list[str] | Field(default_factory=list) |
initial_state | str | '' |
epsilon | float | 0.2 |
max_steps | int | 0 |
agent2_states | list[str] | Field(default_factory=list) |
agent2_unsafe_states | list[str] | Field(default_factory=list) |
agent2_initial_state | str | '' |
epsilon1 | float | 0.1 |
epsilon2 | float | 0.1 |
correlation_rho | float | 0.0 |
target_epsilon | float | 0.2 |
total_T | int | 0 |
total_M | int | 0 |
total_N | int | 0 |
composition_id | str | '' |
input_alphabet | list[str] | Field(default_factory=list) |
budget | int | 10000 |
properties | list[str] | Field(default_factory=list) |
bound | int | 10 |
proof_hint | str | '' |
horizon | int | 0 |
operations | list[str] | Field(default_factory=list) |
max_delay_sec | float | 60.0 |
operation_name | str | '' |
repo_path | str | '' |
transitions | list[dict] | Field(default_factory=list) |
resources | dict | Field(default_factory=dict) |
require_backend | str | '' |
MCPCSFFormalOutput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | str | required |
value | Any | None |
error | str | '' |
degraded | bool | False |
degradation_reason | str \| None | None |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated'] | 'qualified-draft' |
warning_card | dict \| None | None |
evidence | list[dict] | Field(default_factory=list) |
request_id | str | '' |
task_id | str | '' |
run_id | str | '' |
CSFFormalStore¶
Sync SQLite store with 6 tables for CSF formal methods.
Constructor:
| Parameter | Type | Default |
|---|---|---|
db_path | str | ':memory:' |
Methods:
add_ltl(name: str, formula_str: str) -> str¶
get_ltl(lid: str) -> dict[str, Any]¶
list_ltl(limit: int = 100) -> list[dict[str, Any]]¶
delete_ltl(lid: str) -> bool¶
add_composition(result_dict: dict) -> str¶
list_compositions(limit: int = 100) -> list[dict[str, Any]]¶
add_game_result(result_dict: dict) -> str¶
list_game_results(limit: int = 100) -> list[dict[str, Any]]¶
add_formal_check(result_dict: dict) -> str¶
list_formal_checks(backend: str = '', limit: int = 100) -> list[dict[str, Any]]¶
add_rollback_assessment(result_dict: dict) -> str¶
list_rollback_assessments(limit: int = 100) -> list[dict[str, Any]]¶
set_metadata(key: str, value: Any) -> str¶
get_metadata(key: str) -> Any¶
count_all() -> dict[str, int]¶
CSFMCPBlock(AIBlock[MCPCSFInput, MCPCSFOutput, dict])¶
26-op Computational Safety Framework MCP block.
| Field | Type | Default |
|---|---|---|
name | str | 'csf_mcp' |
db_path | str | ':memory:' |
state | dict \| None | None |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(data: MCPCSFInput) -> Result[MCPCSFOutput]¶
MCPCSFInput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | Literal['verify', 'check_safety', 'verify_bounds', 'get_hazard_info', 'git_snapshot', 'git_rollback', 'git_current_sha', 'circuit_check', 'circuit_record_success', 'circuit_record_failure', 'circuit_reset', 'circuit_status', 'log_event', 'list_events', 'clear_events', 'get_event_summary', 'policy_add', 'policy_check', 'policy_list', 'policy_remove', 'incident_report', 'incident_list', 'incident_resolve', 'incident_search', 'system_status', 'list_capabilities'] | required |
agent_states | list[str] | Field(default_factory=list) |
unsafe_states | list[str] | Field(default_factory=list) |
initial_state | str | '' |
epsilon | float | 0.2 |
method | str | 'union_bound' |
max_steps | int | 0 |
operations | list[str] | Field(default_factory=list) |
pairs | list[list] | Field(default_factory=list) |
transitions | list[dict] | Field(default_factory=list) |
resources | dict | Field(default_factory=dict) |
properties | list[str] | Field(default_factory=list) |
unknown_hazard_default | float | 0.05 |
block_unknown_hazard | bool | False |
repo_path | str | '' |
commit_ref | str | 'HEAD~1' |
snapshot_message | str | 'checkpoint' |
circuit_name | str | 'default' |
failure_threshold | int | 5 |
recovery_timeout_sec | float | 60.0 |
event_type | str | '' |
event_data | dict | Field(default_factory=dict) |
limit | int | 100 |
since_iso | str | '' |
policy_name | str | '' |
policy_action | str | '' |
policy_resource | str | '' |
policy_effect | str | 'allow' |
policy_priority | int | 0 |
incident_id | str | '' |
title | str | '' |
severity | str | 'medium' |
description | str | '' |
search_query | str | '' |
MCPCSFOutput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | str | required |
value | Any | None |
error | str | '' |
degraded | bool | False |
degradation_reason | str | '' |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated'] | 'qualified-draft' |
warning_card | dict \| None | None |
evidence | list[dict] | Field(default_factory=list) |
request_id | str | '' |
task_id | str | '' |
run_id | str | '' |
CSFStore¶
Sync SQLite CSF store with 3 tables: events, policies, incidents.
Constructor:
| Parameter | Type | Default |
|---|---|---|
db_path | str | ':memory:' |
Methods:
add_event(event_type: str, data: dict, metadata: dict | None = None) -> str¶
list_events(event_type: str = '', limit: int = 100, since_ts: float = 0.0) -> list[dict[str, Any]]¶
clear_events(event_type: str = '') -> int¶
get_event_summary() -> dict[str, Any]¶
add_policy(name: str, action: str, resource: str, effect: str, priority: int) -> str¶
check_policy(action: str, resource: str) -> dict[str, Any]¶
list_policies() -> list[dict[str, Any]]¶
remove_policy(name: str) -> bool¶
report_incident(title: str, severity: str, description: str) -> str¶
list_incidents(status: str = '', severity: str = '', limit: int = 100) -> list[dict[str, Any]]¶
resolve_incident(incident_id: str) -> bool¶
search_incidents(query: str, limit: int = 20) -> list[dict[str, Any]]¶
count_all() -> dict[str, int]¶
Functions¶
verify_composition(agent1: BoundedAgent, agent2: BoundedAgent, epsilon1: float, epsilon2: float, rho: float = 0.0, target_epsilon: float = 0.2, total_resources: ResourceTriple | None = None) -> CompositionResult¶
Verify compositional safety of two agents under correlated failures.
check_interface_compatibility(agent1: BoundedAgent, agent2: BoundedAgent) -> tuple[bool, list[str]]¶
Check interface compatibility: O₁ ⊆ I₂ via state set intersection.
check_resource_additivity(agent1: BoundedAgent, agent2: BoundedAgent, total: ResourceTriple) -> tuple[bool, list[str]]¶
Check resource additivity: T₁+T₂≤T, M₁+M₂≤M, N₁+N₂≤N.
agent_to_smv(agent: BoundedAgent, ltl_props: list[LTLFormula] | None = None) -> str¶
Convert a BoundedAgent to NuSMV SMV source.
agent_to_smt(agent: BoundedAgent, property: LTLFormula | None = None, bound: int = 10) -> str¶
Encode a BoundedAgent as a QF_LRA bounded model-checking formula.
agent_to_lean(agent: BoundedAgent) -> str¶
Generate a Lean 4 safety theorem for a BoundedAgent.
check_via_z3(agent: BoundedAgent, ltl_property: LTLFormula | None = None, bound: int = 10) -> FormalCheckResult¶
Check safety via Z3 using QF_LRA probabilistic encoding.
check_via_nusmv(agent: BoundedAgent, ltl_property: LTLFormula | None = None) -> FormalCheckResult¶
Check safety via NuSMV — uses PyNuSMVMCPBlock which routes to:
check_via_lean(agent: BoundedAgent, proof_hint: str = '') -> FormalCheckResult¶
Check safety via Lean 4 using LeanProverBlock (7 proof strategies).
verify_all_backends(agent: BoundedAgent, ltl_properties: list[LTLFormula] | None = None, bound: int = 10) -> list[FormalCheckResult]¶
Run all available backends, skip unavailable ones gracefully.
parse_ltl(s: str) -> LTLFormula¶
Parse an LTL formula string into an AST.
evaluate_ltl(formula: LTLFormula, trace: list[dict[str, bool]], pos: int = 0) -> bool¶
Evaluate an LTL formula over a finite trace using standard semantics.
ltl_to_str(formula: LTLFormula) -> str¶
Pretty-print an LTL formula back to string form.
ltl_to_smv(formula: LTLFormula) -> str¶
Convert an LTL formula to NuSMV LTLSPEC syntax.
ltl_to_smt(formula: LTLFormula, bound: int = 10) -> str¶
Convert an LTL formula to bounded SMT-LIB2 encoding.
ltl_to_lean(formula: LTLFormula) -> str¶
Convert an LTL formula to a Lean 4 proposition string.
phi_A_to_ltl(phi_A: Any, state_names: list[str] | None = None) -> LTLFormula¶
Wrap an existing safety predicate phi_A as G(safe).
list_patterns() -> dict[str, Any]¶
Return the csf applied-pattern + skill surface.
compute_trust_boundary(states: list, operations: list[str]) -> frozenset[str]¶
Compute the trust boundary: states where all reversible ops
snapshot_schedule(N: int) -> list[int]¶
Compute snapshot step indices: every ceil(N/10) steps.
solve_game(agent: BoundedAgent, properties: list[LTLFormula], epsilon: float, input_alphabet: list[Any] | None = None, budget: int = 10000, seed: int | None = None) -> GameResult¶
Solve the 2-player safety verification game.
formulate_game(agent: BoundedAgent, properties: list[LTLFormula], epsilon: float, input_alphabet: list[Any] | None = None) -> dict¶
Formulate (but don't solve) the safety game — returns game structure info.
synthesize_monitor(properties: list[LTLFormula]) -> LTLMonitor¶
Build a concrete LTLMonitor for the given safety properties.
find_counterexample(agent: BoundedAgent, property: LTLFormula, input_alphabet: list[Any] | None = None, budget: int = 10000, seed: int | None = None) -> list | None¶
Find an adversarial input sequence that violates the property, or None.
MCP Tools¶
| Operation | Source |
|---|---|
ltl_create | csf_formal_mcp |
ltl_evaluate | csf_formal_mcp |
ltl_check_agent | csf_formal_mcp |
ltl_list | csf_formal_mcp |
ltl_delete | csf_formal_mcp |
compose_verify | csf_formal_mcp |
compose_check_interface | csf_formal_mcp |
compose_check_resources | csf_formal_mcp |
compose_report | csf_formal_mcp |
game_formulate | csf_formal_mcp |
game_solve | csf_formal_mcp |
game_synthesize_monitor | csf_formal_mcp |
game_counterexample | csf_formal_mcp |
bridge_agent_to_smv | csf_formal_mcp |
bridge_agent_to_smt | csf_formal_mcp |
bridge_agent_to_lean | csf_formal_mcp |
bridge_check_z3 | csf_formal_mcp |
bridge_check_nusmv | csf_formal_mcp |
bridge_check_lean | csf_formal_mcp |
bridge_verify_all | csf_formal_mcp |
rollback_check_feasibility | csf_formal_mcp |
rollback_classify_op | csf_formal_mcp |
rollback_trust_boundary | csf_formal_mcp |
rollback_snapshot_schedule | csf_formal_mcp |
system_status | csf_formal_mcp |
list_capabilities | csf_formal_mcp |
verify | csf_mcp |
check_safety | csf_mcp |
verify_bounds | csf_mcp |
get_hazard_info | csf_mcp |
git_snapshot | csf_mcp |
git_rollback | csf_mcp |
git_current_sha | csf_mcp |
circuit_check | csf_mcp |
circuit_record_success | csf_mcp |
circuit_record_failure | csf_mcp |
circuit_reset | csf_mcp |
circuit_status | csf_mcp |
log_event | csf_mcp |
list_events | csf_mcp |
clear_events | csf_mcp |
get_event_summary | csf_mcp |
policy_add | csf_mcp |
policy_check | csf_mcp |
policy_list | csf_mcp |
policy_remove | csf_mcp |
incident_report | csf_mcp |
incident_list | csf_mcp |
incident_resolve | csf_mcp |
incident_search | csf_mcp |
system_status | csf_mcp |
list_capabilities | csf_mcp |