Re-added proper logic for allow_agent