policy
strands_teams.policy ¶
The authority gate: :class:PolicyEngine (ASTR §14, spec 007).
The model never decides a consequential transition — this engine does (AC-3-1). :meth:PolicyEngine.authorize_transition runs an ordered stack of five gates over a :class:~strands_teams.models.TransitionRequest and returns a :class:~strands_teams.models.PolicyVerdict:
capability— the actor's :class:~strands_teams.models.AuthorityGrantmust carry the capability the transition requires (AC-3-2).separation_of_duties— the actor may not be the sole approver of the very transition they request (AC-3-3).human_required— a human-gated transition kind emits a pending :class:~strands_teams.models.HumanDecisionand denies rather than letting the model self-approve (AC-4-1).required_approvals— enough valid, non-expired, signature-verified, revision-bound approvals must be present (AC-3-4); stale approvals (content-hash mismatch) do not count (AC-5-1, AC-5-4).open_blocking_finding— no openblockingfinding may affect the target (AC-3-5).
All inputs are read from invocation_state by reference and never mutated (AC-3-7). The engine is deterministic and does no I/O, so the gate matrix is cheap to test (AC-7-1).
PolicyEngine ¶
Runs the ordered authority-gate stack over a transition (AC-3-1).
Construct one with the run's signing_key, required_approvals threshold, and human_gated_kinds (all from :class:~strands_teams.TeamsSettings), then call :meth:authorize_transition with the transition and the invocation_state dict. The engine reads grants, the approval store, findings, and current revision hashes from that state by reference; it never writes to it (AC-3-7).
Attributes:
| Name | Type | Description |
|---|---|---|
signing_key | Key that approval signatures must verify against; a token that fails verification is treated as absent (AC-1-4). | |
required_approvals | Valid revision-bound approvals a consequential transition needs before the required-approvals gate passes (AC-3-4). | |
human_gated_kinds | Transition kinds that are human-gated (AC-4-1). |
Initialize the engine with the run's policy configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signing_key | str | The approval signing/verification key. | required |
required_approvals | int | Required valid approvals for a consequential transition. | 1 |
human_gated_kinds | Sequence[str] | Transition kinds that must go through a human gate. | () |
Source code in packages/strands-teams/src/strands_teams/policy.py
authorize_transition ¶
Return the final allow/deny verdict for transition (AC-3-1, AC-3-6).
Runs the gate stack in order and short-circuits on the first failure. When every gate passes for a non-human-gated transition, returns allowed=True (AC-3-6). Reads all state from invocation_state by reference and does not mutate it (AC-3-7).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transition | TransitionRequest | The proposed transition to judge. | required |
invocation_state | Mapping[str, Any] | The run state (grants/approvals/findings/revision hashes) read by reference. | required |
now | datetime | None | Clock override for expiry checks (defaults to real UTC now). | None |
Returns:
| Name | Type | Description |
|---|---|---|
A | PolicyVerdict | class: |
PolicyVerdict | the pending :class: |
Source code in packages/strands-teams/src/strands_teams/policy.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
denying_decision ¶
Build an auditable :class:Decision recording a denied transition (AC-4-6).
Used by the runner when a human rejects a gate or the engine refuses a transition, so the denial is captured as a first-class artifact rather than living only in a log line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verdict | PolicyVerdict | The denying verdict. | required |
transition | TransitionRequest | The transition that was refused. | required |
Returns:
| Type | Description |
|---|---|
Decision | A frozen :class: |