Introduction
Tool permission boundaries help control what actions an AI agent can perform, keeping it safe and focused.
Jump into concepts and practice - no test required
tool_permission_boundaries = {
"tool_name": {
"allowed_actions": ["action1", "action2"],
"restricted_data": ["data1", "data2"]
}
}tool_permission_boundaries = {
"email_sender": {
"allowed_actions": ["send_email"],
"restricted_data": ["user_passwords"]
}
}tool_permission_boundaries = {
"file_manager": {
"allowed_actions": ["read_file", "write_file"],
"restricted_data": ["system_files"]
}
}class Tool: def __init__(self, name, permissions): self.name = name self.permissions = permissions def perform_action(self, action): if action in self.permissions.get("allowed_actions", []): return f"{self.name} performed {action}" else: return f"{self.name} is not allowed to perform {action}" # Define permission boundaries permissions = { "calculator": { "allowed_actions": ["add", "subtract"], "restricted_data": [] }, "file_tool": { "allowed_actions": ["read"], "restricted_data": ["secret.txt"] } } # Create tools calculator = Tool("calculator", permissions["calculator"]) file_tool = Tool("file_tool", permissions["file_tool"]) # Test actions print(calculator.perform_action("add")) print(calculator.perform_action("multiply")) print(file_tool.perform_action("read")) print(file_tool.perform_action("write"))
def can_perform(action, permissions):
return action in permissions['allowed'] and action not in permissions['denied']
permissions = {'allowed': ['read', 'write'], 'denied': ['delete']}
action = 'delete'
print(can_perform(action, permissions))def check_permission(action, permissions):
if action in permissions['allowed'] or action not in permissions['denied']:
return True
else:
return False
permissions = {'allowed': ['read'], 'denied': ['delete']}
print(check_permission('delete', permissions))