converge.policy¶
Admission, trust, governance, and safety. AdmissionPolicy implementations (Open, Whitelist, Token) control who can join a pool; pools use them when joining. TrustModel maintains per-agent scores and supports discovery trust thresholds. GovernanceModel implementations resolve disputes: Democratic (majority vote), Dictatorial (single leader), Bicameral (two chambers must agree), Veto (majority with a veto counterpower), Empirical (evidence-weighted votes). Safety provides ResourceLimits, ActionPolicy (allowlist of actions), and validate_safety for resource checks. The StandardExecutor (runtime) accepts an optional safety_policy (ResourceLimits, ActionPolicy) to enforce action allowlists and task resource limits. Pools can set trust_model and trust_threshold; PoolManager.join_pool rejects agents whose trust score is below the threshold.
Custom governance models¶
You can define your own governance by subclassing GovernanceModel and implementing resolve_dispute(context) -> Any:
Subclass
converge.policy.governance.GovernanceModel.Implement
resolve_dispute(self, context: Any) -> Any. Thecontextis whatever the caller provides when resolving a dispute (e.g. a dict with"votes","weights", or custom keys). Return the chosen outcome, orNonefor no decision / deadlock.Use the model either by passing it when creating a pool:
pool_manager.create_pool({"id": "my-pool", "governance_model": my_model}), or by callingmy_model.resolve_dispute(context)yourself when a dispute arises.
The pool stores the instance on pool.governance_model (if provided at creation). Built-in models (Democratic, Dictatorial, Bicameral, Veto, Empirical) document their expected context shape in their docstrings; your custom model can define any contract you need.
- class converge.policy.admission.AdmissionPolicy[source]¶
Bases:
ABCAbstract base class for defining rules on how agents are admitted to a pool.
- class converge.policy.admission.OpenAdmission[source]¶
Bases:
AdmissionPolicyA permissive policy that allows any agent to join.
- class converge.policy.admission.WhitelistAdmission(whitelist: list[str])[source]¶
Bases:
AdmissionPolicyA restrictive policy that only allows agents present in a predefined whitelist.
- class converge.policy.admission.TokenAdmission(required_token: str)[source]¶
Bases:
AdmissionPolicyA policy requiring a specific secret token to be present in the request context.
- class converge.policy.trust.TrustModel[source]¶
Bases:
objectComputes and manages trust scores for agents within the network.
Trust is calculated based on historical interactions, direct feedback, and configured policies.
- class converge.policy.governance.GovernanceModel[source]¶
Bases:
ABCAbstract base class for pool governance models. Determines how decisions are made within a pool (e.g. voting, dictatorial).
Implementing a custom governance model
Subclass
GovernanceModeland implementresolve_dispute(self, context: Any) -> Any. Thecontextis supplied by the caller when resolving a dispute (e.g. a dict with"votes","chamber_a_votes", or any structure your model expects). Return the chosen outcome, orNoneto indicate no decision / deadlock.Example:
class QualifiedMajorityGovernance(GovernanceModel): def __init__(self, threshold: float = 0.66): self.threshold = threshold def resolve_dispute(self, context: Any) -> Any: votes = context.get("votes", []) if isinstance(context, dict) else [] if not votes: return None from collections import Counter count = Counter(votes) top, n = count.most_common(1)[0] return top if n >= len(votes) * self.threshold else None
Pass an instance when creating a pool (e.g.
create_pool({"id": "p1", "governance_model": my_model})) or callresolve_dispute(context)yourself when a dispute arises.
- class converge.policy.governance.DictatorialGovernance(leader_id: str)[source]¶
Bases:
GovernanceModelA single leader makes all critical decisions.
- class converge.policy.governance.DemocraticGovernance[source]¶
Bases:
GovernanceModelDecisions are made by majority vote using Consensus.majority_vote. Expects context to contain a ‘votes’ key (list of vote options).
- class converge.policy.governance.BicameralGovernance[source]¶
Bases:
GovernanceModelTwo chambers must agree (separated powers). Each chamber decides by majority; the final outcome is adopted only if both chambers choose the same option.
Context: dict with “chamber_a_votes” and “chamber_b_votes” (lists of options). Optional “tie_breaker” (any): if chambers disagree, return this instead of None.
- class converge.policy.governance.VetoGovernance(veto_agent_id: str | None = None)[source]¶
Bases:
GovernanceModelCounterpower: a designated agent can veto the outcome of a majority vote. The body votes; if the veto is not exercised, the majority wins; otherwise the decision is blocked (returns None or a fallback).
Context: “votes” (list), “veto_exercised” (bool), optional “veto_agent_id”, optional “fallback” when veto is exercised.
- class converge.policy.governance.EmpiricalGovernance[source]¶
Bases:
GovernanceModelEvidence-weighted decision: votes are combined with weights (e.g. confidence or evidence strength). The option with the highest total weight wins; ties yield None.
Context: “votes” (list of options), optional “weights” (list of float, same length as votes: weight per voter). If “weights” is absent, falls back to unweighted majority.
- class converge.policy.safety.ResourceLimits(max_cpu_tokens: float = 1.0, max_memory_mb: int = 512, max_network_requests: int = 100)[source]¶
Bases:
objectDefines upper bounds for resource consumption by an agent or task.
- class converge.policy.safety.ActionPolicy(allowed_actions: list[str] | None = None)[source]¶
Bases:
objectControls which actions an agent is permitted to execute.
If ‘allowed_actions’ is provided, only those actions are allowed (allowlist). If ‘allowed_actions’ is None, all actions are allowed (permissive).
- converge.policy.safety.validate_safety(limits: ResourceLimits, requested_cpu: float, requested_mem: int) bool[source]¶
Validate that a resource request is within the defined limits.
- Parameters:
limits (ResourceLimits) – The active resource constraints.
requested_cpu (float) – The amount of CPU requested.
requested_mem (int) – The amount of memory requested.
- Returns:
True if within limits, False if exceeded.
- Return type: