Skip to content

Commit 9f342d9

Browse files
author
Ramprasad Gaddam
committed
Add AutoGPT native command adapter
1 parent 924a8d0 commit 9f342d9

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
from vouch import Auditor
3+
4+
# NOTE: In a real AutoGPT install, this import comes from the system.
5+
# We use a dummy decorator here so this file is valid Python in the repo.
6+
try:
7+
from autogpt.command_decorator import command
8+
except ImportError:
9+
def command(*args, **kwargs):
10+
def decorator(func):
11+
return func
12+
return decorator
13+
14+
# Global Auditor Instance (Lazy loaded)
15+
_auditor = None
16+
17+
def _get_auditor():
18+
global _auditor
19+
if _auditor is None:
20+
# Load keys from AutoGPT's .env file or environment
21+
private_key = os.getenv("VOUCH_PRIVATE_KEY")
22+
if not private_key:
23+
raise ValueError("VOUCH_PRIVATE_KEY not found in environment")
24+
_auditor = Auditor(private_key)
25+
return _auditor
26+
27+
@command(
28+
"sign_with_vouch",
29+
"Generates a Vouch-Token to prove identity for sensitive actions",
30+
{
31+
"intent": {
32+
"type": "string",
33+
"description": "A brief description of what you are about to do (e.g. 'read_email')",
34+
"required": True,
35+
},
36+
"target_service": {
37+
"type": "string",
38+
"description": "The domain you are connecting to (e.g. 'api.bank.com')",
39+
"required": True,
40+
}
41+
},
42+
)
43+
def sign_with_vouch(intent: str, target_service: str) -> str:
44+
"""
45+
Returns a Vouch-Token string that should be added to the HTTP Header 'Vouch-Token'.
46+
"""
47+
try:
48+
auditor = _get_auditor()
49+
50+
# The AutoGPT Agent's Identity (Configured in env)
51+
agent_did = os.getenv("VOUCH_DID", "did:web:anonymous-agent")
52+
53+
# Create the proof
54+
vouch_data = {
55+
"did": agent_did,
56+
"integrity_hash": f"{target_service}:{intent}"
57+
}
58+
59+
result = auditor.issue_vouch(vouch_data)
60+
return f"Vouch-Token generated successfully. Add this header to your request: 'Vouch-Token: {result['certificate']}'"
61+
62+
except Exception as e:
63+
return f"Error generating Vouch-Token: {str(e)}"

0 commit comments

Comments
 (0)