maiap-client 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. maiap_client-1.3.0/.gitignore +42 -0
  2. maiap_client-1.3.0/LICENSE.md +65 -0
  3. maiap_client-1.3.0/PKG-INFO +194 -0
  4. maiap_client-1.3.0/README.md +101 -0
  5. maiap_client-1.3.0/SPEC.md +268 -0
  6. maiap_client-1.3.0/aiap_client/__init__.py +36 -0
  7. maiap_client-1.3.0/maiap_client/__init__.py +206 -0
  8. maiap_client-1.3.0/maiap_client/aggregation.py +101 -0
  9. maiap_client-1.3.0/maiap_client/client.py +714 -0
  10. maiap_client-1.3.0/maiap_client/compliance.py +157 -0
  11. maiap_client-1.3.0/maiap_client/consent.py +226 -0
  12. maiap_client-1.3.0/maiap_client/credentials.py +101 -0
  13. maiap_client-1.3.0/maiap_client/delegation.py +338 -0
  14. maiap_client-1.3.0/maiap_client/did.py +249 -0
  15. maiap_client-1.3.0/maiap_client/errors.py +81 -0
  16. maiap_client-1.3.0/maiap_client/eudi.py +268 -0
  17. maiap_client-1.3.0/maiap_client/lifecycle.py +107 -0
  18. maiap_client-1.3.0/maiap_client/models.py +237 -0
  19. maiap_client-1.3.0/maiap_client/signer.py +148 -0
  20. maiap_client-1.3.0/pyproject.toml +42 -0
  21. maiap_client-1.3.0/tests/_fake_broker.py +315 -0
  22. maiap_client-1.3.0/tests/test_aggregation.py +113 -0
  23. maiap_client-1.3.0/tests/test_amendment_2.py +52 -0
  24. maiap_client-1.3.0/tests/test_broker_wire.py +473 -0
  25. maiap_client-1.3.0/tests/test_client.py +179 -0
  26. maiap_client-1.3.0/tests/test_compliance.py +88 -0
  27. maiap_client-1.3.0/tests/test_consent.py +110 -0
  28. maiap_client-1.3.0/tests/test_delegation.py +201 -0
  29. maiap_client-1.3.0/tests/test_deprecated_import_name.py +44 -0
  30. maiap_client-1.3.0/tests/test_did.py +145 -0
  31. maiap_client-1.3.0/tests/test_eudi.py +173 -0
  32. maiap_client-1.3.0/tests/test_lifecycle.py +85 -0
  33. maiap_client-1.3.0/tests/test_model_provider.py +105 -0
  34. maiap_client-1.3.0/tests/test_models.py +146 -0
  35. maiap_client-1.3.0/tests/test_signer.py +103 -0
@@ -0,0 +1,42 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ .eggs/
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+
13
+ # Node
14
+ node_modules/
15
+
16
+ # Go
17
+ bin/
18
+
19
+ # Rust
20
+ target/
21
+
22
+ # .NET
23
+ obj/
24
+
25
+ # Java
26
+ *.class
27
+ out/
28
+
29
+ # IDE
30
+ .idea/
31
+ .vscode/
32
+ .kiro/
33
+ *.swp
34
+
35
+ # OS
36
+ .DS_Store
37
+ Thumbs.db
38
+
39
+ # Secrets (never commit)
40
+ .env
41
+ *.pem
42
+ *.key
@@ -0,0 +1,65 @@
1
+ # aiap-client License
2
+
3
+ Version 1.0, August 2026
4
+
5
+ **Copyright © 2026 Kanjani AI Research & Causum. All rights reserved.**
6
+
7
+ This package implements the AI Agency Protocol (AIAP), a proprietary
8
+ specification. It is **not** open source and **not** source available.
9
+ Publication to a public package index is a distribution convenience and does
10
+ not constitute an open-source grant. Commercial licensing is administered
11
+ exclusively by Causum.
12
+
13
+ ## Free use — Evaluation
14
+
15
+ You may, at no fee and without time limit:
16
+
17
+ - Read, study, and reference this package and the Protocol specification
18
+ - Install and run this package in non-production environments
19
+ - Prototype, experiment with, and test conformance of implementations
20
+ - Publish independent research concerning the Protocol, with attribution
21
+
22
+ "Evaluation Use" means use outside of production operation and not in support
23
+ of any revenue-generating product, service, or business process.
24
+
25
+ ## Paid use — Operating License required
26
+
27
+ You require an Operating License to derive Commercial Value from this package.
28
+ Commercial Value means economic benefit derived from the Protocol, **whether or
29
+ not the Protocol or any implementation of it is itself sold, licensed, or
30
+ otherwise transferred to any third party.** Operating this package in
31
+ production in support of any product, service, or internal business process
32
+ that generates revenue requires an Operating License.
33
+
34
+ Commercial resale of this package, agency-brokerage services whose primary
35
+ value proposition is the Protocol itself, or Protocol-as-a-Service offerings is
36
+ prohibited without a separate commercial license agreement.
37
+
38
+ ## Restrictions
39
+
40
+ You shall not fork, rebrand, or republish this package under a different name
41
+ or identity; remove or alter copyright notices, license headers, or attribution
42
+ statements; or use the names "AIAP" or "AI Agency Protocol" in a product name,
43
+ service name, or marketing material without prior written consent.
44
+
45
+ ## Reservation of rights
46
+
47
+ All patent rights are expressly reserved. No patent license is granted, whether
48
+ expressly, by implication, by estoppel, by publication, by package-index
49
+ distribution, or otherwise. All rights not expressly granted are reserved.
50
+
51
+ ## No warranty
52
+
53
+ THIS PACKAGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55
+ FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56
+ OWNER BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM USE OF
57
+ THIS PACKAGE.
58
+
59
+ ---
60
+
61
+ The full agreement, including the DFARS 252.227-7013 federal-grant carve-out,
62
+ governs this package and is available in the protocol repository:
63
+ https://gitlab.com/causum/aiap/-/blob/main/LICENSE.md
64
+
65
+ Licensing inquiries: owner@ai-governance-protocol.org or licensing@causum.com
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: maiap-client
3
+ Version: 1.3.0
4
+ Summary: Mediated AI Agency Protocol (MAIAP, formerly AIAP) client — identity, scope, and ephemeral authority for AI agents. Import name: maiap_client
5
+ Author-email: Kanjani AI Research & Causum <owner@ai-governance-protocol.org>
6
+ License: # aiap-client License
7
+
8
+ Version 1.0, August 2026
9
+
10
+ **Copyright © 2026 Kanjani AI Research & Causum. All rights reserved.**
11
+
12
+ This package implements the AI Agency Protocol (AIAP), a proprietary
13
+ specification. It is **not** open source and **not** source available.
14
+ Publication to a public package index is a distribution convenience and does
15
+ not constitute an open-source grant. Commercial licensing is administered
16
+ exclusively by Causum.
17
+
18
+ ## Free use — Evaluation
19
+
20
+ You may, at no fee and without time limit:
21
+
22
+ - Read, study, and reference this package and the Protocol specification
23
+ - Install and run this package in non-production environments
24
+ - Prototype, experiment with, and test conformance of implementations
25
+ - Publish independent research concerning the Protocol, with attribution
26
+
27
+ "Evaluation Use" means use outside of production operation and not in support
28
+ of any revenue-generating product, service, or business process.
29
+
30
+ ## Paid use — Operating License required
31
+
32
+ You require an Operating License to derive Commercial Value from this package.
33
+ Commercial Value means economic benefit derived from the Protocol, **whether or
34
+ not the Protocol or any implementation of it is itself sold, licensed, or
35
+ otherwise transferred to any third party.** Operating this package in
36
+ production in support of any product, service, or internal business process
37
+ that generates revenue requires an Operating License.
38
+
39
+ Commercial resale of this package, agency-brokerage services whose primary
40
+ value proposition is the Protocol itself, or Protocol-as-a-Service offerings is
41
+ prohibited without a separate commercial license agreement.
42
+
43
+ ## Restrictions
44
+
45
+ You shall not fork, rebrand, or republish this package under a different name
46
+ or identity; remove or alter copyright notices, license headers, or attribution
47
+ statements; or use the names "AIAP" or "AI Agency Protocol" in a product name,
48
+ service name, or marketing material without prior written consent.
49
+
50
+ ## Reservation of rights
51
+
52
+ All patent rights are expressly reserved. No patent license is granted, whether
53
+ expressly, by implication, by estoppel, by publication, by package-index
54
+ distribution, or otherwise. All rights not expressly granted are reserved.
55
+
56
+ ## No warranty
57
+
58
+ THIS PACKAGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61
+ OWNER BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM USE OF
62
+ THIS PACKAGE.
63
+
64
+ ---
65
+
66
+ The full agreement, including the DFARS 252.227-7013 federal-grant carve-out,
67
+ governs this package and is available in the protocol repository:
68
+ https://gitlab.com/causum/aiap/-/blob/main/LICENSE.md
69
+
70
+ Licensing inquiries: owner@ai-governance-protocol.org or licensing@causum.com
71
+ License-File: LICENSE.md
72
+ Keywords: agency,agents,ai,aiap,credentials,identity,jit,maiap,protocol
73
+ Classifier: Development Status :: 4 - Beta
74
+ Classifier: Intended Audience :: Developers
75
+ Classifier: License :: Other/Proprietary License
76
+ Classifier: Programming Language :: Python :: 3
77
+ Classifier: Programming Language :: Python :: 3.11
78
+ Classifier: Programming Language :: Python :: 3.12
79
+ Classifier: Programming Language :: Python :: 3.13
80
+ Classifier: Topic :: Security
81
+ Requires-Python: >=3.11
82
+ Requires-Dist: httpx>=0.25.0
83
+ Requires-Dist: pydantic>=2.0
84
+ Provides-Extra: aws
85
+ Requires-Dist: boto3>=1.26.0; extra == 'aws'
86
+ Provides-Extra: cert
87
+ Requires-Dist: cryptography>=41.0; extra == 'cert'
88
+ Provides-Extra: dev
89
+ Requires-Dist: pytest; extra == 'dev'
90
+ Requires-Dist: pytest-asyncio; extra == 'dev'
91
+ Requires-Dist: respx; extra == 'dev'
92
+ Description-Content-Type: text/markdown
93
+
94
+ # maiap-client — Mediated AI Agency Protocol (MAIAP) SDK
95
+
96
+ > Published as **`maiap-client`** (formerly `aiap-client`). The import name is unchanged: `import maiap_client`.
97
+
98
+ **Identity is persistent. Agency is ephemeral.**
99
+
100
+ Python SDK for the Mediated AI Agency Protocol (MAIAP). Enables agents to request scoped, time-limited authority from a central broker.
101
+
102
+ ## Install
103
+
104
+ ```bash
105
+ pip install maiap-client
106
+ pip install maiap-client[aws] # + boto3 for credential sessions
107
+ pip install maiap-client[cert] # + cryptography for certificate auth
108
+ ```
109
+
110
+ ## Quick Start
111
+
112
+ ```python
113
+ from maiap_client import AgencyClient, AgencyLevel
114
+
115
+ client = AgencyClient(
116
+ broker_url="https://broker.example.com",
117
+ agent_id="YXFQTW0VCL",
118
+ mac_secret="your-hmac-secret",
119
+ )
120
+
121
+ # Request JIT credentials
122
+ grant = await client.request_agency(
123
+ intent="Invoke underwriting model",
124
+ use_case="underwriting",
125
+ resources=["bedrock:InvokeModel"],
126
+ duration_seconds=900,
127
+ )
128
+
129
+ if grant.granted:
130
+ session = grant.to_boto3_session(region="us-east-1")
131
+ bedrock = session.client("bedrock-runtime")
132
+ # Invoke with scoped creds — expires in 15 min
133
+ else:
134
+ print(f"Denied: {grant.reason}")
135
+ ```
136
+
137
+ ## Token Mode (workload identity, 1.1.0)
138
+
139
+ No shared secret: the agent proves who it is with its own short-lived service token. The broker accepts it only
140
+ when the token carries the capability scope `agency-request:use` and its subject is the caller bound to the
141
+ agent's enrolment (RFC-001 §5.2).
142
+
143
+ ```python
144
+ from maiap_client import AgencyClient, AgencyRefusedError
145
+
146
+ async def current_token() -> str: # your runtime's token source; called for every request
147
+ ...
148
+
149
+ async with AgencyClient(broker_url="https://broker.example.com", agent_id="YXFQTW0VCL",
150
+ token_provider=current_token) as client:
151
+ try:
152
+ grant = await client.require_agency(
153
+ intent="Invoke underwriting model",
154
+ use_case="underwriting",
155
+ resources=["bedrock:InvokeModel"],
156
+ resource_arns=["arn:aws:bedrock:<region>::foundation-model/<model-id>"],
157
+ trace_id=aigp_trace_id, # binds the grant to the MAIGP trace (X-AIGP-Trace-Id)
158
+ )
159
+ except AgencyRefusedError as e: # fail closed: e.code says why (REFUSED, BROKER_UNREACHABLE, ...)
160
+ raise SystemExit(f"no agency: {e}")
161
+ session = grant.to_boto3_session(region="us-east-1")
162
+ ...
163
+ await client.release_grant(grant.decision_id, reason="done") # end it early (no heartbeat)
164
+ ```
165
+
166
+ ## Mediated Execution (Level 2)
167
+
168
+ Agent never sees credentials:
169
+
170
+ ```python
171
+ result = await client.execute(
172
+ intent="Invoke model for risk assessment",
173
+ use_case="underwriting",
174
+ action="bedrock:InvokeModel",
175
+ parameters={"modelId": "<model-id>", "body": {...}},
176
+ )
177
+ print(result.output) # Only the result
178
+ ```
179
+
180
+ ## Certificate Authentication
181
+
182
+ ```python
183
+ from maiap_client import AgencyClient, CertificateSigner
184
+
185
+ client = AgencyClient(
186
+ broker_url="https://broker.example.com",
187
+ agent_id="YXFQTW0VCL",
188
+ signer=CertificateSigner(cert_path="agent.pem", key_path="agent-key.pem"),
189
+ )
190
+ ```
191
+
192
+ ## Protocol
193
+
194
+ See [RFC-001: Mediated AI Agency Protocol](../../../specification/RFC-001-AI-Agency-Protocol.md)
@@ -0,0 +1,101 @@
1
+ # maiap-client — Mediated AI Agency Protocol (MAIAP) SDK
2
+
3
+ > Published as **`maiap-client`** (formerly `aiap-client`). The import name is unchanged: `import maiap_client`.
4
+
5
+ **Identity is persistent. Agency is ephemeral.**
6
+
7
+ Python SDK for the Mediated AI Agency Protocol (MAIAP). Enables agents to request scoped, time-limited authority from a central broker.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install maiap-client
13
+ pip install maiap-client[aws] # + boto3 for credential sessions
14
+ pip install maiap-client[cert] # + cryptography for certificate auth
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```python
20
+ from maiap_client import AgencyClient, AgencyLevel
21
+
22
+ client = AgencyClient(
23
+ broker_url="https://broker.example.com",
24
+ agent_id="YXFQTW0VCL",
25
+ mac_secret="your-hmac-secret",
26
+ )
27
+
28
+ # Request JIT credentials
29
+ grant = await client.request_agency(
30
+ intent="Invoke underwriting model",
31
+ use_case="underwriting",
32
+ resources=["bedrock:InvokeModel"],
33
+ duration_seconds=900,
34
+ )
35
+
36
+ if grant.granted:
37
+ session = grant.to_boto3_session(region="us-east-1")
38
+ bedrock = session.client("bedrock-runtime")
39
+ # Invoke with scoped creds — expires in 15 min
40
+ else:
41
+ print(f"Denied: {grant.reason}")
42
+ ```
43
+
44
+ ## Token Mode (workload identity, 1.1.0)
45
+
46
+ No shared secret: the agent proves who it is with its own short-lived service token. The broker accepts it only
47
+ when the token carries the capability scope `agency-request:use` and its subject is the caller bound to the
48
+ agent's enrolment (RFC-001 §5.2).
49
+
50
+ ```python
51
+ from maiap_client import AgencyClient, AgencyRefusedError
52
+
53
+ async def current_token() -> str: # your runtime's token source; called for every request
54
+ ...
55
+
56
+ async with AgencyClient(broker_url="https://broker.example.com", agent_id="YXFQTW0VCL",
57
+ token_provider=current_token) as client:
58
+ try:
59
+ grant = await client.require_agency(
60
+ intent="Invoke underwriting model",
61
+ use_case="underwriting",
62
+ resources=["bedrock:InvokeModel"],
63
+ resource_arns=["arn:aws:bedrock:<region>::foundation-model/<model-id>"],
64
+ trace_id=aigp_trace_id, # binds the grant to the MAIGP trace (X-AIGP-Trace-Id)
65
+ )
66
+ except AgencyRefusedError as e: # fail closed: e.code says why (REFUSED, BROKER_UNREACHABLE, ...)
67
+ raise SystemExit(f"no agency: {e}")
68
+ session = grant.to_boto3_session(region="us-east-1")
69
+ ...
70
+ await client.release_grant(grant.decision_id, reason="done") # end it early (no heartbeat)
71
+ ```
72
+
73
+ ## Mediated Execution (Level 2)
74
+
75
+ Agent never sees credentials:
76
+
77
+ ```python
78
+ result = await client.execute(
79
+ intent="Invoke model for risk assessment",
80
+ use_case="underwriting",
81
+ action="bedrock:InvokeModel",
82
+ parameters={"modelId": "<model-id>", "body": {...}},
83
+ )
84
+ print(result.output) # Only the result
85
+ ```
86
+
87
+ ## Certificate Authentication
88
+
89
+ ```python
90
+ from maiap_client import AgencyClient, CertificateSigner
91
+
92
+ client = AgencyClient(
93
+ broker_url="https://broker.example.com",
94
+ agent_id="YXFQTW0VCL",
95
+ signer=CertificateSigner(cert_path="agent.pem", key_path="agent-key.pem"),
96
+ )
97
+ ```
98
+
99
+ ## Protocol
100
+
101
+ See [RFC-001: Mediated AI Agency Protocol](../../../specification/RFC-001-AI-Agency-Protocol.md)
@@ -0,0 +1,268 @@
1
+ # MAIAP Python SDK — Specification
2
+
3
+ **Package:** `maiap-client`
4
+ **Version:** 1.1.0
5
+ **Wire protocol:** MAIAP `protocol_version` `1.0` (the on-the-wire message contract; distinct from this SDK's release version)
6
+ **Python:** >=3.11
7
+ **Dependencies:** `httpx>=0.25.0`, `pydantic>=2.0`
8
+
9
+ ---
10
+
11
+ ## Purpose
12
+
13
+ The `maiap-client` SDK enables agents, applications, and helpers to:
14
+ 1. Request agency (JIT credentials or mediated execution)
15
+ 2. Authenticate with MAC or certificate, or in token mode with their own service token (workload identity, no
16
+ shared secret; RFC-001 §5.2)
17
+ 3. Manage credential lifecycle (refresh, revoke)
18
+ 4. Record agency decisions for audit
19
+
20
+ ---
21
+
22
+ ## Public API
23
+
24
+ ```python
25
+ from maiap_client import (
26
+ # Core
27
+ AgencyClient,
28
+
29
+ # Models
30
+ AgencyRequest,
31
+ AgencyGrant,
32
+ AgencyDeny,
33
+ AgencyRevoke,
34
+ AgencyLevel,
35
+ SafetyTier,
36
+
37
+ # Credentials
38
+ AgencyCredentials,
39
+ CredentialSession,
40
+
41
+ # Authentication
42
+ MacSigner,
43
+ CertificateSigner,
44
+ )
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Usage
50
+
51
+ ### Basic: Request JIT Credentials
52
+
53
+ ```python
54
+ from maiap_client import AgencyClient, AgencyRequest, AgencyLevel
55
+
56
+ client = AgencyClient(
57
+ broker_url="https://broker.example.com",
58
+ agent_id="YXFQTW0VCL",
59
+ mac_secret="d918eb5081ca19eaf6081882df70e3cd...",
60
+ )
61
+
62
+ # Request agency
63
+ grant = await client.request_agency(
64
+ intent="Invoke underwriting model for applicant risk assessment",
65
+ use_case="underwriting",
66
+ resources=["bedrock:InvokeModel"],
67
+ resource_arns=["arn:aws:bedrock:<region>::foundation-model/<model-id>"],
68
+ duration_seconds=900,
69
+ )
70
+
71
+ if grant.granted:
72
+ # Use the scoped credentials
73
+ session = grant.to_boto3_session()
74
+ bedrock = session.client("bedrock-runtime", region_name="us-east-1")
75
+ # ... invoke model with JIT creds
76
+ else:
77
+ print(f"Denied: {grant.reason}")
78
+ ```
79
+
80
+ ### Level 2: Mediated Execution
81
+
82
+ ```python
83
+ result = await client.execute(
84
+ intent="Invoke underwriting model",
85
+ use_case="underwriting",
86
+ action="bedrock:InvokeModel",
87
+ parameters={
88
+ "modelId": "<model-id>",
89
+ "body": {"messages": [...]},
90
+ },
91
+ )
92
+ # Agent never sees credentials — only the result
93
+ print(result.output)
94
+ ```
95
+
96
+ ### Revoke
97
+
98
+ ```python
99
+ await client.revoke(decision_id="dec-a1b2c3d4e5f6")
100
+ ```
101
+
102
+ ### Certificate Authentication
103
+
104
+ ```python
105
+ from maiap_client import AgencyClient, CertificateSigner
106
+
107
+ signer = CertificateSigner(
108
+ cert_path="/path/to/agent-cert.pem",
109
+ key_path="/path/to/agent-key.pem",
110
+ )
111
+
112
+ client = AgencyClient(
113
+ broker_url="https://broker.example.com",
114
+ agent_id="YXFQTW0VCL",
115
+ signer=signer,
116
+ )
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Module Design
122
+
123
+ ### `models.py`
124
+
125
+ ```python
126
+ class AgencyLevel(str, Enum):
127
+ JIT_CREDENTIALS = "JIT_CREDENTIALS"
128
+ MEDIATED = "MEDIATED"
129
+ DELEGATED = "DELEGATED"
130
+
131
+ class SafetyTier(str, Enum):
132
+ LOW = "LOW"
133
+ MEDIUM = "MEDIUM"
134
+ HIGH = "HIGH"
135
+ CRITICAL = "CRITICAL"
136
+
137
+ class AgencyRequest(BaseModel):
138
+ agent_id: str
139
+ mac_credential: str = "" # MAC hex or "cert:<base64>"; "" = token mode (RFC-001 §5.2, §5.3)
140
+ intent: str
141
+ use_case: str
142
+ resources: list[str]
143
+ resource_arns: list[str] = []
144
+ context: dict = {}
145
+ level: AgencyLevel = AgencyLevel.JIT_CREDENTIALS
146
+ duration_seconds: int = 900
147
+
148
+ class AgencyCredentials(BaseModel):
149
+ access_key_id: str
150
+ secret_access_key: str
151
+ session_token: str
152
+ expiration: str
153
+
154
+ class AgencyGrant(BaseModel):
155
+ granted: bool = True
156
+ decision_id: str
157
+ credentials: AgencyCredentials | None = None
158
+ source_identity: str = ""
159
+ session_name: str = ""
160
+ tags: dict = {}
161
+ scope: dict = {}
162
+ governance_checks: list[str] = []
163
+ expires_at: str = ""
164
+
165
+ class AgencyDeny(BaseModel):
166
+ granted: bool = False
167
+ decision_id: str
168
+ reason: str
169
+ governance_checks: list[str] = []
170
+ code: str = "REFUSED" # DenyCode, RFC-001 §5.5
171
+
172
+ class AgencyRelease(BaseModel): # AGENCY_RELEASE, RFC-001 §11.2
173
+ agent_id: str
174
+ decision_id: str
175
+ reason: str = ""
176
+ mac_credential: str = "" # MAC / certificate mode only
177
+ timestamp: str = ""
178
+ nonce: str = ""
179
+
180
+ class ReleaseResult(BaseModel):
181
+ released: bool
182
+ decision_id: str
183
+ already_released: bool = False
184
+ session_expires_at: str = ""
185
+ ```
186
+
187
+ `AgencyRequest(credential=...)` / `MediatedRequest(credential=...)` (the 1.0 keyword) still constructs, with a
188
+ `DeprecationWarning`, and is stored as `mac_credential`; `credential` is never put on the wire.
189
+
190
+ ### `client.py`
191
+
192
+ ```python
193
+ class AgencyClient:
194
+ def __init__(self, broker_url, agent_id, mac_secret="", signer=None, *,
195
+ token=None, token_provider=None, timeout=10.0, transport=None): ...
196
+ async def request_agency(self, intent, use_case, resources, ..., *, trace_id=None) -> AgencyGrant | AgencyDeny: ...
197
+ async def require_agency(self, intent, use_case, resources, **kwargs) -> AgencyGrant # or AgencyRefusedError
198
+ async def release_grant(self, decision_id, reason="", *, trace_id=None) -> ReleaseResult # typed errors
199
+ async def execute(self, intent, use_case, action, parameters, **kwargs) -> ExecutionResult: ... # MAC mode
200
+ async def revoke(self, decision_id) -> bool: ... # operator (RFC-001 §11.1), needs an operator token
201
+ async def heartbeat(self, decision_id) -> bool: ... # withdrawn: sends nothing, False, DeprecationWarning
202
+ async def list_sessions(self) -> list[dict]: ...
203
+ async def list_decisions(self, limit=20) -> list[dict]: ...
204
+ ```
205
+
206
+ **Auth modes (1.1.0, RFC-001 §5.2).** Exactly one per client: `signer` / `mac_secret` (MAC or certificate), or
207
+ `token` / `token_provider` (token mode). Otherwise `AgencyConfigError` (a `ValueError`). In token mode the
208
+ client sends `Authorization: Bearer <token>` and no `mac_credential` / `timestamp` / `nonce`. `token_provider`
209
+ (sync or async callable) is called for every request. An empty, non-string or multi-line token, or a provider
210
+ that raises, sends nothing (`TOKEN_UNAVAILABLE`). The token is never logged. Messages that token mode does not
211
+ cover (`execute`, `delegate`, `set_lifecycle_state`, `request_consent`) raise `AgencyConfigError` before
212
+ sending.
213
+
214
+ **Trace (RFC-001 §5.4).** `trace_id=` is sent as `X-AIGP-Trace-Id`. A malformed id raises `AgencyConfigError`
215
+ before anything is sent.
216
+
217
+ **Fail closed (RFC-001 §5.5).** Only `granted is True` with a well-formed grant, carrying `decision_id` and, for
218
+ `JIT_CREDENTIALS`, credentials, is a grant. Everything else is an `AgencyDeny` with `code` in `REFUSED`,
219
+ `AUTH_REFUSED`, `TOKEN_UNAVAILABLE`, `BROKER_UNREACHABLE`, `BROKER_ERROR`, `MALFORMED_RESPONSE`,
220
+ `LEVEL_UNSUPPORTED`. `require_agency` raises `AgencyRefusedError` with the same code. `release_grant` raises
221
+ `AgencyConfigError`, `AgencyTokenError`, `AgencyTransportError`, `AgencyAuthError` (401/403),
222
+ `AgencyNotFoundError` (404 `GRANT_NOT_FOUND`), `AgencyBrokerError` (any other error, including a broker without
223
+ the release route) or `AgencyProtocolError` (the answer does not confirm this grant). All of them derive from
224
+ `AgencyError`.
225
+
226
+ ### `credentials.py`
227
+
228
+ ```python
229
+ class CredentialSession:
230
+ """Wraps AgencyCredentials with auto-refresh."""
231
+ def __init__(self, client, grant): ...
232
+ def to_boto3_session(self, region="us-east-1") -> boto3.Session: ...
233
+ async def refresh(self) -> None: ...
234
+ async def release(self, reason="", *, trace_id=None) -> ReleaseResult: ...
235
+ @property
236
+ def is_expired(self) -> bool: ... # 1.1.0: missing / unparseable expiry = expired (fail closed)
237
+ @property
238
+ def expires_in_seconds(self) -> int: ...
239
+ ```
240
+
241
+ ### `signer.py`
242
+
243
+ ```python
244
+ class Signer(Protocol):
245
+ def sign(self, agent_id: str) -> str: ... # legacy (deprecated, replayable)
246
+ def sign_request(self, agent_id: str, *, timestamp: str, # request-bound (v1.0.1+)
247
+ nonce: str, body_hash: str) -> str: ...
248
+
249
+ class MacSigner:
250
+ """HMAC-SHA256 signing (bootstrap/legacy)."""
251
+ def __init__(self, secret: str): ...
252
+
253
+ class CertificateSigner:
254
+ """X.509 certificate signing (production)."""
255
+ def __init__(self, cert_path: str = "", key_path: str = "",
256
+ cert_pem: str = "", key_pem: str = ""): ...
257
+ ```
258
+
259
+ **Credential binding (v1.0.1+).** Credentials are signed over a per-request canonical message
260
+ `agent_id \n timestamp \n nonce \n sha256(body)` (not the bare `agent_id`), so a captured
261
+ credential cannot be replayed. `AgencyClient` generates a fresh `timestamp`+`nonce` per call and
262
+ sends them alongside `mac_credential` (RFC-001 §5.3; 1.0 named it `credential`); the broker verifies the binding and rejects stale timestamps
263
+ or reused nonces. The legacy `sign(agent_id)` remains for older brokers but is deprecated. See
264
+ RFC-001 §5.1.
265
+
266
+ **Resource management.** `AgencyClient` is an async context manager — prefer
267
+ `async with AgencyClient(...) as client:` so the underlying HTTP client is always closed;
268
+ `await client.close()` remains available for manual lifecycle.