A Ulysses Contract is a self-binding commitment the agent makes in advance, restricting a set of action indices even when future incentives might favour overriding that restriction. Formally, a contractDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/xcoder-es/governance-layer/llms.txt
Use this file to discover all available pages before exploring further.
U = <A_restrict, φ, ψ, κ> pairs a set of forbidden action indices with a high revocation bar (ψ) that exceeds the normal enactment threshold (φ), and one or more enforcement mechanisms (κ) that make bypass structurally costly. The ContractRegistry tracks all contracts and exposes the union of live restrictions as a single mask that the Parliament applies before passing decisions to the optimizer.
ContractState
Defined in governance/contracts/contract.py. Each UlyssesContract moves through these states across its lifecycle.
| State | Description |
|---|---|
PROPOSED | Initial state. The contract exists in the registry but is not yet active — no restrictions are enforced. |
ENACTED | The parliament has voted to enact the contract (vote ≥ enactment_threshold). Restrictions are now live. |
ACTIVE | Explicitly activated via activate(). Equivalent to ENACTED for restriction purposes — both states pass the is_active check. |
REVOKED | Revoked by a parliament supermajority (vote ≥ revocation_threshold). The contract no longer restricts any actions. |
EXPIRED | Reserved for time-based expiry. No automatic transition occurs in the current implementation. |
ENACTED and ACTIVE cause is_active to return True, so restrictions are applied in either state.
UlyssesContract
A dataclass representing a single binding contract. Fields with defaults are optional at construction time.
Constructor
A unique string identifier for this contract (e.g.
"ban_loans", "no_self_modification"). Used by ContractRegistry.get_by_id() for lookups.The set of action indices this contract forbids. An action at index
i is blocked for the optimizer when the contract is active and i ∈ restricted_indices.The parliament vote fraction
φ required to move this contract from PROPOSED to ENACTED. Defaults to two-thirds supermajority.The parliament vote fraction
ψ required to revoke an active contract. Defaults to unanimous consent, making revocation structurally harder than enactment — the asymmetry is the core of the Ulysses mechanism.The enforcement strategy
κ applied at runtime. Accepted values: "procedural_inertia", "distributed_monitors", "timelock". Stacked enforcement can be applied by calling stacked_enforcement() directly.The current lifecycle state. Normally set via
enact(), activate(), or revoke() rather than at construction.When using the
"timelock" enforcement mode, specifies the block height at which the timelock expires. A value of 0 means no timelock is active.The governance cycle number at which this contract was created. Used for auditing and future expiry logic.
The governance cycle number at which this contract was revoked. Populated by the caller when
revoke() is invoked; None while the contract is still active.Methods
enact()
PROPOSED to ENACTED. After this call, is_active returns True and restrictions are enforced. Typically called by the parliament once the enactment vote meets enactment_threshold.
activate()
ACTIVE. Functionally equivalent to ENACTED for restriction checks — both states satisfy is_active. Use activate() when an explicit two-step enactment/activation flow is required.
revoke()
REVOKED. Once revoked, is_active returns False and the contract no longer contributes any restricted indices to the registry mask.
applies_to(action_index) -> bool
True if this contract is active and the given action index is in restricted_indices. Returns False for any contract in PROPOSED, REVOKED, or EXPIRED state, regardless of the action index.
The integer index of the action to check against this contract’s restriction set.
True when the contract is active (ENACTED or ACTIVE) and action_index ∈ restricted_indices. False otherwise.Property: is_active
True when the contract’s state is either ENACTED or ACTIVE. This is the canonical check used by ContractRegistry to build the live restriction mask.
ContractRegistry
Manages a collection of UlyssesContract instances and exposes aggregate views over active restrictions.
Constructor
0.
Methods
add(contract)
PROPOSED or REVOKED) may be added — only active ones affect the restriction mask.
The contract instance to register.
get_active() -> List[UlyssesContract]
is_active is True (state is ENACTED or ACTIVE).
A list of currently active
UlyssesContract instances. Empty list if none are active.get_by_id(contract_id) -> Optional[UlyssesContract]
None if no contract with that ID exists in the registry.
The
contract_id string to search for.The matching contract, or
None if not found.tick_cycle()
active_restrictions() -> Set[int]
restricted_indices across all active contracts. This is the primary method used by the Parliament–Contract merger to compute the final action mask.
A set of all action indices currently blocked by at least one active contract. Returns an empty set when no contracts are active.
Enforcement Functions
Defined ingovernance/contracts/enforcement.py. Three enforcement modes can be applied individually or composed with stacked_enforcement.
EnforcementResult
| Field | Type | Description |
|---|---|---|
compliant | bool | True if the contract’s constraints are currently satisfied; False if a violation was detected. |
reason | str | Human-readable explanation of the compliance outcome. |
DistributedMonitor
enforce_distributed_monitors. Each instance wraps a user-supplied callable that decides whether a given action index is acceptable in context. The cost of bypassing distributed enforcement scales with the number of independent monitors — a single compromised evaluator cannot clear the full set.
A unique string identifier for this monitor. Used in logging and diagnostics to trace which monitor raised a violation.
A function with signature
(action_index: int, context: Any) -> bool. Return True if the action passes this monitor’s check, False to signal a violation.check(action_index, context) -> bool
evaluate_fn(action_index, context) and returns its result. Called once per monitor by enforce_distributed_monitors.
The action index being evaluated.
Arbitrary context forwarded unchanged to
evaluate_fn.True if evaluate_fn returns True (no violation); False otherwise.enforce_procedural_inertia(contract, parliament_vote) -> EnforcementResult
contract.revocation_threshold. This is the asymmetric inertia mechanism — the status quo is restriction, not permissiveness.
The contract to evaluate. The function reads
contract.revocation_threshold.The aggregated parliament vote fraction for revocation, in
[0, 1]. If this value meets or exceeds revocation_threshold, the result is non-compliant (i.e. revocation is triggered).compliant=False with reason "Revocation threshold met" when parliament_vote >= revocation_threshold. Otherwise compliant=True.enforce_distributed_monitors(monitors, action_index, context) -> EnforcementResult
DistributedMonitor independently evaluates the action. A single failing monitor does not necessarily block — the result reports total violation count. All monitors must pass for compliant=True.
The list of independent monitor instances. Each monitor exposes a
check(action_index, context) -> bool method backed by a user-supplied evaluate_fn.The action index being evaluated against the monitors.
Arbitrary context passed to each monitor’s
evaluate_fn. Its schema is defined by the monitor implementations.compliant=False with reason "Violated N/M monitors" if any monitors fail. compliant=True with "All monitors passed" if all pass.enforce_timelock(contract, current_block) -> EnforcementResult
current_block < contract.timelock_blocks. Once the block height reaches or exceeds the timelock value, the lock expires and the result is non-compliant. A timelock_blocks value of 0 or less is treated as no timelock.
The contract to evaluate. Reads
contract.timelock_blocks.The current block height or cycle count. Compared against
contract.timelock_blocks to determine whether the lock is still active.compliant=True with remaining block count when the lock is still active. compliant=False when current_block >= timelock_blocks. compliant=True with "No timelock" when timelock_blocks <= 0.stacked_enforcement(contract, parliament_vote, monitors, action_index, context, current_block) -> EnforcementResult
compliant=True with "All enforcement modes passed". This is the recommended entry point when a contract uses composed enforcement.
The contract subject to stacked enforcement.
Aggregated vote fraction passed to
enforce_procedural_inertia.Monitor list passed to
enforce_distributed_monitors.Action index passed to
enforce_distributed_monitors.Context passed to
enforce_distributed_monitors.Block height passed to
enforce_timelock.The first non-compliant result encountered, or
compliant=True if all three modes pass.Usage Example
Creating a contract, registering it, and querying active restrictions:Mask Merging with merger.py
The governance/contracts/merger.py module bridges contracts and the Parliament’s decision output. It provides two functions:
-
merge_masks(decision, registry) -> GovernanceDecision— takes aGovernanceDecisionwhosegovernance_meta["action_mask"]holds the parliament-approved action indices, subtracts the registry’sactive_restrictions(), and writes the final reduced mask back intogovernance_meta. The decision’sgovernance_metais annotated with"contract_restrictions_applied"(count of restricted indices removed) and"final_action_count"(size of the resulting mask). -
apply_restrictions(allowed_indices, restricted) -> Set[int]— a lower-level utility that computes the set differenceallowed_indices - restricted. Use this when you need to apply contract restrictions to an arbitrary index set outside the fullGovernanceDecisionpipeline.
A_final = A_mask ∩ (∩ U_i.A_restrict)ᶜ — an action reaches the optimizer only if the parliament permits it and no active contract blocks it.