pyagent-dns API Reference¶
pyagent_dns
¶
pyagent-dns: Agent naming plane and authority graph for multi-agent systems.
Action
¶
Bases: StrEnum
What a principal may do with a capability.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
AttenuationError
¶
Bases: Exception
Raised when a delegate would hold more authority than its parent.
Attributes:
| Name | Type | Description |
|---|---|---|
dimension |
The field that would widen, for example |
|
parent_value |
The parent's value. |
|
requested_value |
The requested value. |
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
AuthorityGraph
¶
Grants and the delegation links between them, plus call-time authorization.
Not thread-safe; see NameRegistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
NameRegistry | None
|
Registry the graph reports coverage against. |
None
|
clock
|
Callable[[], float] | None
|
Epoch-seconds time source. Defaults to the registry's, else wall-clock time. |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
registry
property
¶
The bound registry, if any.
add_grant(grant)
¶
Add a grant and return its id.
A grant that names a parent is checked against it: the parent must exist and allow delegation, and the grant must not exceed it on any dimension. The graph therefore holds no grant broader than its parent, however the grant was authored.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the id is already used, or the parent is missing. |
AttenuationError
|
If the grant exceeds its parent. |
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
add_grants(grants)
¶
Add several grants, parents before children whatever their order in the input.
All or nothing: if any grant is rejected, none of them are added.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
get_grant(grant_id)
¶
Return a grant, or None if it is unknown or revoked.
grants_for(principal, action=None)
¶
Return a principal's unrevoked, unexpired grants. Ancestry is not checked.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
revoke(grant_id)
¶
Revoke a grant. Returns True if it was present and not already revoked.
Grants delegated from it stop authorizing on the next check, because every check validates the whole chain.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
is_revoked(grant_id)
¶
revoke_record(name, version=None)
¶
Revoke a record in the bound registry, so both halves of an incident response can be done from one handle.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
delegate(parent_grant_id, *, delegate_principal, scope)
¶
Issue a grant to delegate_principal that is no broader than its parent.
Fields left None in scope are inherited. Capability, action, and effect are
always inherited: a delegate that needs a different capability needs its own grant
from a policy owner, and delegation can never weaken an approval requirement.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the parent is unknown, revoked, or expired. |
AttenuationError
|
If the parent does not allow delegation, the scope exceeds
the parent on any dimension, or the parent requires attenuation and the
scope narrows nothing. |
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
effective_limit(principal_chain, action, capability, resource, *, purpose=None)
¶
Return the limits that would bind this call, or None if no grant authorizes it.
Uses the same grant selection as :meth:authorize. Pass purpose when grants for
the same capability differ by purpose, since their limits may differ.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
reachable(principal, purpose=None)
¶
Return the sorted capabilities a principal can currently reach.
A grant counts only if it is live and its whole delegation chain is intact.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
uncovered()
¶
Return the sorted names of usable records that no live grant covers.
A grant covers a record when its capability is the record's name or one of the record's capabilities, and its name scope, if set, is that record's name.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no registry is bound. Returning |
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
authorize(principal_chain, action, capability, resource, context, resolution=None)
¶
Decide whether principal_chain may perform action on capability.
Checks run in a fixed order and the first failure is named in the decision's reason code: the resolved record (revoked, expired, signature, verification), then a covering grant (existence, purpose, data coverage, expiry, delegation chain), then limits, then the grant's effect. A discovered or verified record is never enough on its own.
When a resolution is given, its record is authoritative about what is being
touched. The record's data classes are a floor under whatever the caller declares, so
a caller cannot understate sensitivity, and the record's name is the name scope.
capability must be the record's name or one of its declared capabilities.
Pure given the graph, the registry state, and the injected clock: no I/O.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
CallContext
dataclass
¶
Facts about one call, supplied by the caller.
calls_in_session, records_requested, and amount are taken on trust: a caller
that always passes zero has disabled that limit. DnsMiddleware keeps a real session
counter; a direct caller of authorize must supply one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purpose
|
str
|
Why this call is being made. |
required |
session_id
|
str | None
|
Identifies the session, for logging. |
None
|
calls_in_session
|
int
|
Calls already made this session. |
0
|
records_requested
|
int | None
|
Records this call asks for, if known. |
None
|
amount
|
float | None
|
Amount this call would spend, if any. |
None
|
currency
|
str | None
|
Currency of |
None
|
request_payload
|
bytes | None
|
Exact request bytes. An approval is bound to their SHA-256 and the bytes themselves are never stored. |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
Decision
dataclass
¶
The result of an authorization check, with the evidence needed to explain it later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outcome
|
Outcome
|
|
required |
reason_code
|
str
|
Stable code naming the check that decided it. |
required |
reason
|
str
|
Human-readable explanation. |
required |
principal
|
str
|
The leaf principal the check was for. |
required |
action
|
Action
|
Action requested. |
required |
capability
|
str
|
Capability requested. |
required |
grant_path
|
tuple[str, ...]
|
Grant ids root first, leaf last, that authorized the call. |
()
|
effective_limits
|
Limits | None
|
Limits intersected along that path. |
None
|
obligations
|
tuple[Obligation, ...]
|
What must be done for an allow to be honored. |
()
|
approval_binding
|
str | None
|
|
None
|
data_classes
|
tuple[str, ...]
|
Data classes the check evaluated: what the caller declared plus what the resolved record declares. |
()
|
record_name
|
str | None
|
Record the call resolved to. |
None
|
record_fingerprint
|
str | None
|
Digest of the exact record bytes resolved. |
None
|
record_version
|
str | None
|
Version resolved. |
None
|
record_verification
|
VerificationStatus | None
|
Signature verification outcome for that record. |
None
|
policy_versions
|
tuple[str, ...]
|
Versions of the policies that issued the grants on the path. |
()
|
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
allowed
property
¶
True for ALLOW and ALLOW_WITH_OBLIGATIONS only.
to_dict()
¶
Return the decision as a plain dictionary.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
DelegationResult
dataclass
¶
DelegationTerms
dataclass
¶
Whether a grant may be delegated.
must_attenuate means a delegate must hold strictly less authority than the grant
on at least one dimension. When False, a delegate may hold an equal grant. In neither
case may a delegate hold more: attenuation is a ceiling.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
to_dict()
¶
from_dict(data, *, where='delegation')
classmethod
¶
Build from a mapping. Values must be real booleans.
bool("false") is True, so a quoted YAML value is rejected rather than coerced.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
DelegationToken
dataclass
¶
A structured record of a delegation chain.
It is data, not a signed credential: the issuer and the checker are the same process in 0.1, so the graph can re-derive and re-check the chain. A portable signed format is a later decision.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
Grant
dataclass
¶
Permission for one principal to perform one action on one capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grant_id
|
str
|
Stable identifier. Decision logs and delegation chains refer to it. |
required |
principal
|
str
|
Who holds the grant. |
required |
action
|
Action
|
What it permits. |
required |
capability
|
str
|
What it applies to: a record name, or one of a record's capabilities. |
required |
resource
|
ResourceSelector
|
Data the grant covers. |
ResourceSelector()
|
purpose
|
str
|
Why the grant exists. A call for a different purpose is not covered. |
''
|
limits
|
Limits
|
Numeric ceilings. |
Limits()
|
delegation
|
DelegationTerms
|
Whether and how the grant may be delegated. |
DelegationTerms()
|
effect
|
GrantEffect
|
|
ALLOW
|
approver_role
|
str | None
|
Who should approve, for |
None
|
granted_by
|
str
|
Policy that issued it. |
''
|
policy_version
|
str
|
Version of that policy, so a log can name the deciding policy. |
''
|
expires
|
datetime | None
|
Timezone-aware expiry, or |
None
|
parent_grant_id
|
str | None
|
The grant this was delegated from, if any. |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
is_expired(now=None)
¶
Return whether the grant's expiry has passed at now (default: current UTC time).
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
to_dict()
¶
Return the grant as a plain dictionary that :meth:from_dict accepts.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
from_dict(data, *, where='grant')
classmethod
¶
Build a grant from a mapping.
grant_id, principal, action, capability, and purpose are required,
and unknown keys are rejected. A misspelled effect must not fall back to
allow, and an id generated at load time would differ on every run and could not
be referenced by a delegation or a decision log.
A single granted_by: policy_v14 is accepted and split into granted_by and
policy_version when policy_version is absent.
Raises:
| Type | Description |
|---|---|
GrantLoadError
|
On a missing, unknown, or malformed field. |
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
GrantEffect
¶
Bases: StrEnum
What a matching grant does: allow outright, or hold the call for approval.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
GrantScope
dataclass
¶
The scope requested for a delegate. None means inherit the parent's value.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
Limits
dataclass
¶
Numeric ceilings. None means this link does not bound that dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_records_per_call
|
int | None
|
Most records one call may request. |
None
|
max_calls_per_session
|
int | None
|
Most calls allowed within one session. |
None
|
max_amount
|
float | None
|
Largest amount one call may spend. A grant that sets this must set
|
None
|
currency
|
str | None
|
Currency |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
to_dict()
¶
Return the limits as a plain dictionary.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
from_dict(data, *, where='limits')
classmethod
¶
Build from a mapping, rejecting unknown keys.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
Obligation
¶
Bases: StrEnum
Something the caller must do for an allow to be honored. One that cannot be done is a deny.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
Outcome
¶
Bases: StrEnum
The four structured results of an authorization check.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
ResourceSelector
dataclass
¶
The data a call touches, or the data a grant covers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_classes
|
tuple[str, ...]
|
Sensitivity classes. A grant covers a request when its highest class
is at least the request's highest class, so a grant for |
()
|
account_scope
|
str | None
|
Account the call is for. A grant that sets it requires an exact match. |
None
|
name_scope
|
str | None
|
Exact record name; there are no glob patterns in 0.1. |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
to_dict()
¶
Return the selector as a plain dictionary.
from_dict(data, *, where='resource')
classmethod
¶
Build from a mapping, rejecting unknown keys.
Source code in packages/pyagent-dns/src/pyagent_dns/authority.py
DnsBundle
dataclass
¶
A blueprint's dns configuration, loaded and wired together.
Source code in packages/pyagent-dns/src/pyagent_dns/blueprint.py
DnsExtensionSpec
¶
Bases: BaseModel
The shape of the x-pyagent:dns block. Unknown keys are rejected.
Source code in packages/pyagent-dns/src/pyagent_dns/blueprint.py
AuthorizationDeniedError
¶
Bases: Exception
Raised when an agent handoff is denied. decision carries the structured reason.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
AuthorizedAgent
¶
Bases: Agent
An agent whose run first checks authorization. Build with wrap_agent.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
run(messages)
async
¶
Authorize, run the wrapped agent, and apply any obligation to its reply.
Raises:
| Type | Description |
|---|---|
AuthorizationDeniedError
|
If the call is denied, requires approval (an agent handoff has no request payload to bind an approval to), or an obligation cannot be honored. |
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
DnsMiddleware
¶
Resolve a name, check the grants, and enforce the answer at call time.
Every decision is appended to :attr:decisions and, if an event bus is wired, emitted as
an authority_decision trace event. The decision list grows for the life of the
middleware; clear it by discarding the middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolver
|
Resolver
|
Resolves capability names to verified records. |
required |
graph
|
AuthorityGraph
|
Grants and delegation chains. |
required |
event_bus
|
Any
|
Optional |
None
|
approver
|
ApproverFn | None
|
Called for |
None
|
redactor
|
Any
|
A |
None
|
session_counter
|
SessionCounter | None
|
Counter for session limits. A private one is created if omitted. |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
decisions
property
¶
A copy of every decision made, in order.
authorize_call(*, principal_chain, action, capability, resource, context)
¶
Resolve capability as a record name, check the grants, and record the decision.
High-risk actions resolve fresh, bypassing the cache. Does not run approvals or obligations; a caller that integrates directly handles those itself.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
guard_tools(tools, *, principal_chain, purpose, action=Action.CALL, session_id=None)
¶
Return tools with every function wrapped in an authorization check.
Each dict key is resolved as a record name, so a tools dict whose keys are not
record names is denied with NO_RECORD. That is correct, and it is how drifted
names get noticed. A denied call returns DENIED [REASON_CODE] reason instead of
raising, because ReAct feeds the result back to the model as an observation and the
model can replan. The denied function is never invoked.
Limits that need request facts (records_requested, amount) cannot be derived
from a ReAct call's single input string, so they are enforced only through
authorize_call. Session limits are enforced here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str | None
|
Scopes the call counter. Defaults to a fresh id per |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
wrap_agent(agent, *, principal, purpose, session_id=None)
¶
Wrap an agent so that calling it is authorized first.
Calling the agent counts as CALL on the capability named by agent.name,
performed by principal. The check runs before the LLM call, so a denied handoff
spends no model call. A denial raises :class:AuthorizationDeniedError, because a
pattern awaiting agent.run has no channel for a deny string, and fabricating an
assistant message would put words in the target agent's mouth.
Only handoffs through the returned object are governed. Supervisor holds its
routes directly, so wrapping a classifier does not govern the specialists it routes
to: wrap the specialists.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
wrap_all(agents, *, principal, purpose)
¶
Wrap several agents with the same principal and purpose.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
SessionCounter
¶
Counts calls per session and capability, for max_calls_per_session.
Not thread-safe: it is a plain dict, like the registries. Sessions are only as real as the ids callers give them.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
count(session_id, capability)
¶
Return calls made so far in this session for this capability.
increment(session_id, capability)
¶
Record a call and return the new count.
reset(session_id=None)
¶
Clear one session's counts, or every session's.
Source code in packages/pyagent-dns/src/pyagent_dns/middleware.py
Identity
dataclass
¶
Identity claims and key reference carried by a record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_key_fingerprint
|
str
|
|
required |
public_key
|
str | None
|
Optional signing key, base64 raw Ed25519 or PEM. Informational only: verification never trusts a key supplied by the record itself. |
None
|
workload_id
|
str | None
|
Optional workload identifier, for example a SPIFFE ID. |
None
|
signed_by
|
str
|
Name of the signer, a key into the trusted keys file. |
''
|
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
to_dict()
¶
Return the identity as a plain dictionary.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
from_dict(data, *, where='identity')
classmethod
¶
Build an Identity from a mapping, rejecting unknown or missing keys.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
NameRecord
dataclass
¶
A versioned record naming an agent, tool, provider, data source, or approver.
The record is the naming plane: it says what something is and who vouches for it.
It grants nothing. Permissions live in :class:pyagent_dns.authority.Grant.
capabilities and data_classes are tuples so that a signed record cannot be
altered through a shared list. Lists passed to the constructor are converted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique identifier, for example |
required |
kind
|
RecordKind
|
Entity type. |
required |
version
|
str
|
Semantic version string. |
required |
endpoint
|
str
|
Invocation URI or reference. Resolution never connects to it. |
required |
identity
|
Identity
|
Signer and key details. |
required |
schema_hash
|
str
|
|
required |
capabilities
|
tuple[str, ...]
|
Declared capability names, used for discovery. |
required |
data_classes
|
tuple[str, ...]
|
Sensitivity classes this record touches; a floor that callers cannot understate when authorization is evaluated. |
required |
owner
|
str
|
Responsible team. |
required |
status
|
RecordStatus
|
Lifecycle status declared by the owner. |
ACTIVE
|
expires
|
datetime | None
|
Timezone-aware expiry, or |
None
|
ttl_seconds
|
int
|
How long a resolution may be cached. |
300
|
signature
|
str | None
|
Base64 Ed25519 signature over :meth: |
None
|
signature_algorithm
|
str
|
Signature algorithm; only |
'ed25519'
|
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
fingerprint
property
¶
sha256: digest of :meth:canonical_bytes, the stable name of these exact bytes.
canonical_bytes()
¶
Return the exact bytes that are signed: sorted-key compact JSON, UTF-8.
signature is excluded. The _pyagent_dns marker is a domain separator, so a
signature over a record cannot be replayed as a signature in another protocol.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
is_expired(now=None)
¶
Return whether the record's expiry has passed at now (default: current UTC time).
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
to_dict()
¶
Return the record as a plain dictionary that :meth:from_dict accepts.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
from_dict(data, *, where='record')
classmethod
¶
Build a record from a mapping.
Every field without a default in the dataclass is required, and unknown keys are rejected, so a typo cannot silently change what is signed or granted.
Raises:
| Type | Description |
|---|---|
RecordLoadError
|
On a missing, unknown, or malformed field. |
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
from_agent_card(card, *, owner, expires, identity, data_classes)
classmethod
¶
Import an A2A Agent Card as an unsigned agent record.
A card carries a name, URL, version, and skills. It does not say who owns the agent,
when its authority should lapse, who vouches for it, or what data it touches, so the
caller must say so. Nothing is guessed. expires=None is an explicit choice of no
expiry. Capability names come from each skill's id (falling back to name).
schema_hash is the SHA-256 of the card as imported, so a changed card is a
changed record. The result is unsigned; sign it with sign_record.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the card lacks a name, url, version, or usable skill, or the caller supplies an empty owner or an identity with no signer or fingerprint. |
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
RecordInfo
dataclass
¶
A summary of a stored record. status is the effective lifecycle status, which
includes operator revocation, and verification is computed by the verifier.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
RecordKind
¶
Bases: StrEnum
The kind of entity named by a NameRecord.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
RecordLoadError
¶
RecordStatus
¶
Bases: StrEnum
Lifecycle status the record's owner declared inside the signed payload.
Source code in packages/pyagent-dns/src/pyagent_dns/records.py
NameRegistry
¶
Versioned store of signed records, with capability discovery and revocation.
Records are keyed by (name, version) so several versions of one name can coexist.
revoke records the revocation in the registry and leaves the stored record exactly
as the owner signed it. Rewriting the record's status would break its signature and
change its fingerprint, and an audit log would then report a legitimately revoked record
as failed. Use :meth:status_of for the effective lifecycle status.
Revocation lasts for the registry's lifetime: re-registering a revoked (name,
version) does not restore it. Reload from files to clear it.
Not thread-safe. Like ProviderRegistry, it assumes single-process, event-loop use;
serialize access yourself if you mutate it from several threads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trusted_keys
|
TrustedKeys | None
|
Keys records are verified against. With none, every record is
|
None
|
clock
|
Callable[[], float]
|
Returns the current time in epoch seconds. Inject one in tests instead of sleeping. |
time
|
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
trusted_keys
property
writable
¶
The keys records are verified against.
clock
property
¶
The time source, in epoch seconds.
generation
property
¶
Counter that increases on every change that could alter a resolution.
count
property
¶
Number of stored records, counting each version.
now()
¶
register(record)
¶
Store a record, replacing any record with the same name and version.
Unsigned and unverifiable records are accepted, because a registry may hold them for review. Verification is reported, and enforced at authorization time.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
register_many(records)
¶
Store several records as one change.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
from_directory(path, *, trusted_keys=None)
classmethod
¶
Build a registry from every record file under a directory.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
status_of(name, version)
¶
Effective lifecycle status of one version, or None if it is not stored.
REVOKED if the owner declared it or an operator revoked it here.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
get(name, version=None)
¶
Return a record as published.
With version, returns exactly that version or None. Without it, returns the
newest version that is neither revoked nor expired. If every version is revoked or
expired it returns the newest anyway, so a caller can tell "this name was revoked"
from "this name never existed". Check :meth:status_of before relying on the result.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
list_records()
¶
Summarize every stored record, including its computed verification status.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
discover(required_capabilities=None, *, kind=None, verified_only=True)
¶
Find records whose capabilities include every required capability.
Matching is exact set inclusion, the same semantics as ProviderRegistry.discover.
Each name contributes at most its newest version that is usable (not revoked or
expired) and passes the filters. Unverified records are excluded unless
verified_only is False; discovery never implies permission to call.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
verify(name, version=None)
¶
Verify a stored record's signature. UNVERIFIED if absent or no keys are set.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
expire(now=None)
¶
Report names whose versions have newly crossed their expiry. Nothing is deleted.
An expired record stays stored so a decision log that names its fingerprint can
still be explained. Each (name, version) is reported once.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
revoke(name, version=None)
¶
Revoke one version, or every version of name. Returns whether anything changed.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
remove(name, version=None)
¶
Delete one version, or every version of name, including its revocation.
Source code in packages/pyagent-dns/src/pyagent_dns/registry.py
Resolution
dataclass
¶
The result of resolving a name: a record, and what is known about it right now.
Lifecycle and verification are separate facts. status is the effective lifecycle
status, including operator revocation. verification is computed by the verifier, and
a record cannot declare its own verification outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
NameRecord
|
The record as published and signed. |
required |
version
|
str
|
Exact version resolved. |
required |
fingerprint
|
str
|
Digest of the signed bytes. Stable across revocation, so a decision log can name exactly what was resolved. |
required |
resolved_at
|
float
|
Epoch seconds, from the resolver's clock. |
required |
verified
|
bool
|
Whether |
required |
verification
|
VerificationStatus
|
Signature verification outcome. |
required |
status
|
RecordStatus
|
Effective lifecycle status. |
ACTIVE
|
from_cache
|
bool
|
Whether this was served from the TTL cache. |
False
|
Source code in packages/pyagent-dns/src/pyagent_dns/resolver.py
Resolver
¶
Resolve names to verified records, caching each result for the record's TTL.
The cache is dropped whenever the registry changes, and a revoked or expired record is never served from it. Resolution is a local lookup plus a signature check. It never connects to the record's endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
NameRegistry
|
The registry to resolve against. |
required |
clock
|
Callable[[], float] | None
|
Epoch-seconds time source. Defaults to the registry's, so TTLs and record expiry always agree. |
None
|
Source code in packages/pyagent-dns/src/pyagent_dns/resolver.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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 | |
cache_size
property
¶
Number of cached resolutions.
invalidate(name=None)
¶
Drop the whole cache, or only the entries for name.
Source code in packages/pyagent-dns/src/pyagent_dns/resolver.py
resolve(name, version=None)
¶
Resolve name, using the cache while the entry is within the record's TTL.
Returns None only if the name was never registered. A revoked or expired record
still resolves, with that fact in status, because "revoked" and "never existed"
are different audit facts.
Source code in packages/pyagent-dns/src/pyagent_dns/resolver.py
resolve_fresh(name, version=None)
¶
Resolve and verify without consulting the cache. Used for high-risk actions.
Source code in packages/pyagent-dns/src/pyagent_dns/resolver.py
resolve_capability(capability)
¶
Resolve every usable record that declares capability, verified or not.
Source code in packages/pyagent-dns/src/pyagent_dns/resolver.py
VerificationStatus
¶
Bases: StrEnum
Outcome of checking a record's signature. Computed by the verifier, never read from a file.
UNVERIFIED means nothing was proven false: the record is unsigned, its signer is not
trusted, or it pins a key this reader does not trust. FAILED means a trusted key was
found and the signature does not match, which is a stronger and more alarming result.
Source code in packages/pyagent-dns/src/pyagent_dns/signing.py
load_blueprint_dns(path)
¶
Load a blueprint's x-pyagent:dns block into a wired :class:DnsBundle.
Relative file references resolve against the blueprint's directory, not the working
directory. Returns None if the blueprint has no dns block.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the blueprint file does not exist. |
DnsBlueprintError
|
If the block, or any file it references, is invalid. The message
names the blueprint. With |