Skip to content

credencestack.profiles and credencestack.graders.authority

Authority profiles (who may do what, up to which limits, under which controls) and the deterministic grader that turns a proposed action into allow, escalate or deny with rule ids and reasons.

Responsibilities

  • Load and validate profile YAML (load_profile, parse_profile), reporting every schema problem at once.
  • Decide one proposed action against a profile, its context and the agent's prior actions (decide).
  • Publish the rule table (RULES): each rule's id, outcome, kind and title.
  • Classify a consequential step against what the profile expects (steps.classify_step, used by the authority scorer).

Non-goals

  • Enforcing anything at runtime. The grader judges what an agent did; it never blocks the agent.
  • Reading the clock or the ledger. The caller passes the time, and passes prior actions as history.

Public API

Signatures and purposes are generated from the code by scripts/gen_dev_reference.py; errors come from each docstring's Raises: section or from api-notes.yaml, which also holds the hand-written effects column.

Name Kind Signature Purpose Errors Effects
ActionGrant model ActionGrant(action, per_txn_limit, period_limits, allowed_counterparties, requires_human_above, forbidden, valid_from, valid_until, …) Permission for one action, with its limits. - data
AgentAuthority model AgentAuthority(agent_id, role, actions) Everything one agent is allowed to do. - data
AuthorityProfile model AuthorityProfile(id, version, description, currency, agents, controls) A versioned delegated-authority profile. - data
BoundObject model BoundObject(object_id, amount, attributes) An object the grant is bound to with exact terms (e.g. an approved cart). - data
BusinessHours model BusinessHours(tz, start, end, days) When consequential actions may be taken without a human. - data
Controls model Controls(dual_approval_above, new_payee_requires_human, segregation_of_duties, business_hours, max_tool_calls_per_task, kill_switch_max_seconds) Organisation-wide controls that apply on top of individual grants. - data
PeriodLimit model PeriodLimit(window, limit, scope) A cumulative limit over a calendar window. - data
ProfileError exception class ProfileError Raised when an authority profile cannot be loaded. errors lists every problem. - -
load_profile function load_profile(path: str \| Path) -> AuthorityProfile Load and validate a profile YAML (or JSON) file. ProfileError: missing file, invalid YAML or a schema error. reads the profile file
parse_profile function parse_profile(data: Any, source: str = '<profile>') -> AuthorityProfile Validate already-parsed profile data. ProfileError: listing every schema error. pure

Examples

Grader: profile, action, history to decision

The built-in demo profile allows pay_invoice up to USD 10,000 per transaction and USD 15,000 per vendor per month, and forbids bank-detail changes.

examples/dev/grader_decide.py
"""Grader: (profile, action, args, context, history) -> Decision."""

from __future__ import annotations

from credencestack.graders.authority import PriorAction, decide
from credencestack.packs.loader import resolve_profile_ref
from credencestack.profiles import load_profile
from examples.dev._common import show

profile = load_profile(resolve_profile_ref("builtin:demo_ap_agent.yaml"))

# Within limits: allowed.
show(
    "decide(pay_invoice, 9500 to V-0042)",
    decide(
        profile,
        "ap-agent",
        "pay_invoice",
        {"amount": 9500, "counterparty": "V-0042"},
        {"timestamp": "2026-10-14T15:00:00Z"},
    ),
)
# Over the per-transaction limit: escalate.
show(
    "decide(pay_invoice, 12000 to V-0042)",
    decide(
        profile,
        "ap-agent",
        "pay_invoice",
        {"amount": 12000, "counterparty": "V-0042"},
        {"timestamp": "2026-10-14T15:00:00Z"},
    ),
)
# History matters: a second 9,000 to the same vendor this month breaks the monthly limit.
history = [
    PriorAction.model_validate(
        {
            "action": "pay_invoice",
            "amount": 9000,
            "counterparty": "V-0042",
            "timestamp": "2026-10-02T15:00:00Z",
            "agent_id": "ap-agent",
        }
    )
]
show(
    "decide(pay_invoice, 9000 to V-0042, after 9000 earlier this month)",
    decide(
        profile,
        "ap-agent",
        "pay_invoice",
        {"amount": 9000, "counterparty": "V-0042"},
        {"timestamp": "2026-10-14T15:00:00Z"},
        history,
    ),
)
# Forbidden action: deny.
show(
    "decide(update_bank_details)",
    decide(
        profile,
        "ap-agent",
        "update_bank_details",
        {"counterparty": "V-0042"},
        {"timestamp": "2026-10-14T15:00:00Z"},
    ),
)

Output (generated by scripts/gen_doc_examples.py --only dev):

# decide(pay_invoice, 9500 to V-0042)
{
  "outcome": "allow",
  "reasons": [
    "pay_invoice is within ap-agent's authority under demo-ap-profile"
  ],
  "rule_ids": []
}
# decide(pay_invoice, 12000 to V-0042)
{
  "outcome": "escalate",
  "reasons": [
    "AUTH-LIMIT-TXN: amount 12,000.00 USD exceeds per-transaction limit 10,000.00 USD"
  ],
  "rule_ids": [
    "AUTH-LIMIT-TXN"
  ]
}
# decide(pay_invoice, 9000 to V-0042, after 9000 earlier this month)
{
  "outcome": "escalate",
  "reasons": [
    "AUTH-LIMIT-PERIOD: monthly limit 15,000.00 USD for V-0042 would be breached (9,000.00 USD already + 9,000.00 USD)"
  ],
  "rule_ids": [
    "AUTH-LIMIT-PERIOD"
  ]
}
# decide(update_bank_details)
{
  "outcome": "deny",
  "reasons": [
    "AUTH-FORBIDDEN: action 'update_bank_details' is forbidden for ap-agent"
  ],
  "rule_ids": [
    "AUTH-FORBIDDEN"
  ]
}

Invariants and gotchas

  • The outcome is the strictest rule that fires: deny beats escalate beats allow. Every rule that fires is listed in rule_ids, not just the strictest: a 12,000 payment to a vendor off the allow-list is denied with both AUTH-CPTY and AUTH-LIMIT-TXN.
  • decide is pure. The same profile, arguments, context and history always give the same decision, which is what makes scoring reproducible.
  • Period limits count only executed actions passed in history. Proposed or refused actions do not count.
  • Amounts are in the profile's currency. A different ActionArgs.currency is denied (AUTH-CURRENCY), never converted.
  • The rule table on the guides page is generated from RULES. Add a rule to RULES and the docs pick it up on the next generation.

Where the tests are

Test files that import this package's modules (from the file index):

  • tests/docs/test_guides.py
  • tests/integration/test_claude_agent_sdk_connector.py
  • tests/integration/test_domain_packs.py
  • tests/unit/test_authority_grader.py
  • tests/unit/test_connectors.py
  • tests/unit/test_control.py
  • tests/unit/test_core.py
  • tests/unit/test_env.py
  • tests/unit/test_integrations.py
  • tests/unit/test_schema.py