Repository navigation
Expand file tree
/
Copy pathagentkey_integration.py
More file actions
65 lines (54 loc) · 1.76 KB
/
Copy pathagentkey_integration.py
File metadata and controls
65 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
"""
examples/agentkey_integration.py
--------------------------------
Runnable example showing ToolBoundary × AgentKey integration.
Flow:
1. ToolBoundary evaluates local policy (tool permitted, access mode, autonomy).
2. On local ALLOW, call is frozen with deterministic SHA-256 call digest.
3. AgentKeyProvider evaluates external authorization in ENFORCE mode.
4. Tool executes safely.
5. Post-dispatch execution evidence is recorded with AgentKey session correlation.
"""
from __future__ import annotations
from toolboundary import (
AccessMode,
AutonomyLevel,
Boundary,
ProviderMode,
ToolPermission,
guarded_tool,
)
from toolboundary.integrations.agentkey import AgentKeyProvider
# In production, pass an authenticated AgentKey client:
# provider = AgentKeyProvider(client=agentkey_client)
# Without arguments, AgentKeyProvider runs in standalone simulated mode
# for local demos and development without external network credentials.
provider = AgentKeyProvider()
boundary = Boundary(
agent_name="agentkey-demo",
autonomy=AutonomyLevel.AUTONOMOUS,
permissions=[
ToolPermission(
"read_ticket",
access_mode=AccessMode.READ_ONLY,
),
],
provider=provider,
provider_mode=ProviderMode.ENFORCE,
policy_version="demo-v1",
)
@guarded_tool(
boundary,
tool_name="read_ticket",
access_mode=AccessMode.READ_ONLY,
)
def read_ticket(ticket_id: str) -> str:
return f"ticket={ticket_id}"
def main() -> None:
print("--- ToolBoundary × AgentKey Integration Demo ---")
print(f"Session ID: {provider.session_id}")
output = read_ticket(ticket_id="INC-1001")
print(f"Execution Output: {output}")
print("--- Demo Completed Successfully ---")
if __name__ == "__main__":
main()